Intelligent Telegram Bot for Sales Automation

High-load hybrid system for sales automation, lead qualification, and user support — built for the education niche.

EdTech AI / LLM Automation

About the project

We built a high-load, intelligent Telegram bot designed to automate sales workflows, qualify leads, and support users for education products.

The solution is a hybrid system that combines a classic scripted sales funnel (powered by a Finite State Machine) with generative AI (LLM) to enable natural, personalized dialogue with prospects.

The bot acts as the first line of the sales team: it operates 24/7, handles inbound requests, nurtures the audience, and routes “hot” clients to managers.

Telegram bot interface

User-facing functionality (Client)

For the end user, interacting with the bot feels like speaking to a competent consultant who understands context and helps choose the right solution — not just a set of canned replies.

Natural dialogue powered by AI

The user asks questions in free form. Using LLM, the bot understands intent, answers product‑specific questions, handles objections, and keeps context across the conversation.

Client dialog example 1
Client dialog example 2

Personalized sales funnel

The bot guides the user through funnel stages: discovery and needs analysis to product presentation and closing. The flow adapts to user responses with relevant content.

Buffering and smart replies

Debounce/Buffering: when a user sends multiple short messages in a row (e.g., "Hi", "How much?", "Any installments?"), the bot avoids spam and responds once with a single, comprehensive answer.

Access to materials and bonuses

Users can receive useful files, guides, and presentations right in chat—on demand or as rewards for completing questionnaire steps.

Multimedia support

The bot handles not only text but also images with captions and voice messages (with transcription), making communication convenient for users.

Functionality and benefits for the company

For business, the bot scales sales, reduces manager workload, and increases conversion through instant responses and high‑quality qualification.

Automatic Lead Scoring

The system analyzes every user message and assigns a "warmth" score using heuristics and AI semantic analysis. This enables segmentation and directs sellers’ attention to the most promising leads.

Lead scoring system 1
Lead scoring system 2
Lead scoring system 3

Intelligent lead handoff

The bot decides when to transfer the dialog to a live manager: upon high score, explicit user request ("want to call"), or complex edge cases. A lead card with history and context is instantly sent to the admin channel or CRM.

Full-featured CRM inside Telegram

  • Admin panel: Manage products, pricing, and content without code edits.
  • Request management: Managers pick up requests, change statuses, view client profiles, and message them directly via the bot UI.
  • Notifications: Instant alerts for new leads and user actions.
Bot admin panel 1
Bot admin panel 2
Bot admin panel 3
Bot admin panel 4
Bot admin panel 5
Bot admin panel 6

Powerful marketing toolkit

  • Broadcasts: Launch segmented mass messaging, including A/B testing for titles and content.
  • Follow‑up chains: Automatic reminders to re‑engage users who went silent for 24/72 hours.
  • Context awareness: All automated messages are logged into the dialog history so AI "remembers" what was sent and can continue the discussion.

Analytics and reporting

Built‑in metrics collection (users, conversions, sales, broadcast efficiency) with data export capability.

Technologies and Integrations

The project is built on a modern tech stack that ensures high performance, resilience, and security.

Backend

Python 3.11+, FastAPI (for webhook and metrics API), aiogram 3.x (async framework for Telegram).

Artificial Intelligence

OpenAI API integration (GPT‑4/GPT‑4o mini) for answer generation and semantic analysis. RAG (Retrieval‑Augmented Generation) is used to query the product knowledge base.

Databases

  • PostgreSQL: Primary storage (users, messages, transactions, leads). SQLAlchemy 2.0 and asyncpg are used for async access.
  • Redis: Caches FSM states, stores temporary message buffers, enables idempotency (duplicate protection), and coordinates distributed tasks.

Infrastructure

DB migrations Alembic
Scheduler APScheduler
Monitoring Prometheus
Process manager Systemd

Architectural features

  • FSM (Finite State Machine): Clear control over funnel states.
  • Idempotency Middleware: Protects from duplicate update processing on network glitches.
  • High Concurrency: Tuned connection pools and workers support 1000+ concurrent active dialogs.

Architecture & components

The project is split into several clear layers (Clean Architecture):

app/ ├── handlers/ # Telegram entry points (handlers) │ ├── start.py, dialog.py │ ├── admin_full.py # Admin console │ └── application.py # Lead intake │ ├── services/ # Business logic layer (core) │ ├── llm_service.py # OpenAI integration │ ├── lead_scoring.py # Scoring algorithms │ ├── broadcast.py # Broadcaster │ └── analytics.py # Metrics collector │ ├── fsm/ # Finite State Machine │ ├── transitions.py # Transition map │ └── engine.py # State engine │ ├── repositories/ # Data access layer (DB) ├── middlewares/ # Pipeline (anti-spam, throttling) └── main.py # FastAPI application

Implementation results

Implementation created an autonomous sales channel that efficiently processes inbound traffic.

Routine automation

The bot handles 100% of first contacts, filters out low‑quality traffic, and answers FAQs — freeing managers for key clients.

Faster response time

Response time reduced to seconds — critical for keeping attention in messengers. Buffering made bot replies more human‑like and complete.

Uninterrupted operation

Thanks to a microservice architecture and queues, the bot remains stable under load, without losing messages even during marketing peaks and mass broadcasts.

Process transparency

The client gained full control over the sales funnel via detailed dialog logging and transparent analytics, tracking script effectiveness and A/B tests in real time.

Built by the IT-AI team

We create intelligent solutions that work

Discuss your project