8000
Skip to content

Repository files navigation

πŸš— Tire Service Bot

NestJS TypeScript PostgreSQL Docker Telegram

A comprehensive Telegram Bot for managing Tire Service workflows.
Developed for a service station in Dnipro, Ukraine πŸ‡ΊπŸ‡¦


πŸ“– Overview

This bot is designed to automate and streamline the operations of a tire service station. It includes a robust order management system, role-based access control for employees (Admins, Masters), and customer-facing features like warranty verification via QR codes.

It efficiently handles the entire lifecycle of a service order, from creation to completion, generating PDF warranty certificates, and tracking performance statistics.

✨ Key Features

  • Order Management: Create, track, and update service orders in real-time.
  • Role-Based Access Control (RBAC):
    • ADMIN: Full system control, analytics, and order management.
    • MASTER: Manage assigned orders and view personal stats.
    • USER (Customer): Verify warranties and check current order status.
  • Warranty Verification: Generate unique QR codes for orders. Customers can scan to verify warranty validity instantly.
  • PDF Generation: Automatic generation of warranty certificates (PDF) with sending via Email/Telegram.
  • Google Sheets Integration: Sync staff data and backup order history automatically.
  • Search & Reporting: Advanced search by phone number and detailed statistics summaries.

πŸ› οΈ Tech Stack

  • Framework: NestJS (Node.js)
  • Language: TypeScript
  • Database: PostgreSQL with Prisma ORM
  • Bot API: telegraf
  • PDF Generation: pdf-lib
  • Integrations: Google Sheets API (google-spreadsheet), Nodemailer
  • Containerization: Docker & Docker Compose

πŸš€ Getting Started

Prerequisites

  • Node.js (v20+)
  • Docker & Docker Compose
  • PostgreSQL (if running locally without Docker)
  • A Telegram Bot Token (from @BotFather)
  • Google Service Account Credentials (for Sheets integration)

Installation

  1. Clone the repository

    git clone https://github.com/horoshi10v/tire-service-bot
    cd tire-service-bot
  2. Install dependencies

    npm install
  3. Configure Environment Variables

    Copy the example configuration file and update it with your credentials:

    cp .env.example .env

    Make sure to fill in your Telegram Bot Token, Database URL, and Google Credentials.

Running the Application

Development Mode

# Start the database (if using Docker for DB only)
docker-compose up db -d

# Run migrations
npx prisma migrate dev

# Start the app
npm run start:dev

Production Mode (Docker)

docker-compose up -d --build

The application will start, and the bot will be ready to accept commands.

πŸ“± Bot Commands

For Staff (Admin/Master)

Menu Buttons:

Button Description
πŸ†• Новий Create a new order (starts by uploading a photo)
πŸ” ΠŸΠΎΡˆΡƒΠΊ Interactive search by phone number
πŸ“Œ Π’Ρ–Π΄ΠΊΡ€ΠΈΡ‚ΠΈ замовлСння Open an order by ID
πŸ“Š Бтатистика Show current order statistics
🟑 ΠŸΡ€ΠΈΠΉΠ½ΡΡ‚Ρ– List orders with status Accepted
πŸ”΅ Π’ Ρ€ΠΎΠ±ΠΎΡ‚Ρ– List orders with status In Progress
🟒 Π“ΠΎΡ‚ΠΎΠ²Ρ– List orders with status Ready
⚫ Π’ΠΈΠ΄Π°Π½Ρ– List orders with status Done

Text Commands:

Command Description Access
/start Open the main menu All
/active <id> Open a specific order by ID Master, Admin
/search Search for an order by phone number Master, Admin
/edit <id> Edit an existing order Master, Admin
/delete <id> CONFIRM Delete an order permanently Admin only
/backup Backup all orders to Google Sheets Admin only
/sync_staff Sync staff list from Google Sheets Admin only
/restore CONFIRM Restore orders from Backup sheet Admin only

For Customers

Command / Button Description
/start verify_<token> Verify a warranty certificate (usually scanned via QR)
πŸ“‹ Бтатус замовлСння Check the status of your current order

πŸ” Role Management

Roles (ADMIN, MASTER) are managed in the database or synchronized via the Google Sheets integration.

Initially, you may need to insert the first Admin manually into the database:

INSERT INTO "Employee" ("tgId", "name", "role", "isActive")
VALUES (YOUR_TELEGRAM_ID, 'Admin Name', 'ADMIN', true);

πŸ—οΈ Project Structure

src/
β”œβ”€β”€ common/             # Domain logic, events, guards, & exceptions
β”œβ”€β”€ config/             # Environment configuration
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ auth/           # Authentication service
β”‚   β”œβ”€β”€ bot/            # Telegram bot logic (Commands, Handlers, Flows)
β”‚   β”œβ”€β”€ integrations/   # External APIs (Google Sheets)
β”‚   β”œβ”€β”€ mail/           # Email sending service
β”‚   β”œβ”€β”€ notifications/  # Notification strategies
β”‚   β”œβ”€β”€ orders/         # Order business logic & CRUD
β”‚   β”œβ”€β”€ pdf/            # PDF generation (Fonts, Icons, Generators)
β”‚   └── warranty/       # Warranty verification logic
β”œβ”€β”€ prisma/             # Database connection & schema
└── main.ts             # Application entry point

πŸ“„ License

This project is licensed under the MIT License.


Built with ❀️ for Dnipro Tire Services

About

πŸš— Telegram bot for tire service management built with NestJS, featuring PDF generation, QR codes, Emails, Google Sheets integration, and PostgreSQL database.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0