Autonomous Conversational Lead Qualification & Edge CRM Router for Telegram
An ultra-responsive, zero-fluff agentic bot that engages prospective inbound clients on Telegram 24/7, qualifies project requirements via interactive inline keyboards and deterministic state machine reasoning, schedules discovery calls via Cal.com, and synchronizes qualified leads to databases and CRM webhooks.
ββββββββββββββββββββββββββββββββββββββββββββββββ
β TELEGRAM ECOSYSTEM β
β User Chat / Direct Message / Channel Link β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β
HTTPS / JSON Payload
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β TELEFLOW INGESTION ENGINE β
β β’ Webhook Route (/webhook) β
β β’ Resilient Long-Poller (Dev / Worker) β
β β’ Secret Token Header Verification β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β 4-PHASE DETERMINISTIC STATE MACHINE β
β INITIAL βββΊ DISCOVERY βββΊ QUALIFICATION β
β ββββΊ CONFIRMED β
βββββββββ¬βββββββββββββββββββββββββββββββ¬ββββββββ
β β
Interactive UI β β Multi-Sink Dispatch
βΌ βΌ
ββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββ
β β’ Inline Keyboard Buttons β β β’ Supabase Database Sink β
β β’ Callback Query Router β β β’ Outbound Signed Webhook β
β β’ Cal.com Scheduling Bridge β β β’ Admin Instant Push Alert β
ββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββ
INITIAL: Welcomes the prospective client, highlights core capabilities, and presents one-tap service selection buttons.DISCOVERY: Analyzes natural language project briefs, maps requests to verified service categories, and extracts initial scopes.QUALIFICATION: Requests target launch timelines and contact details with dynamic inline keyboard chips (Urgent < 1 Wk,2β4 Weeks,1β2 Months,Flexible).CONFIRMED: Packages the validated intake schema, stores the lead in the persistent CRM, sends real-time push alerts, and provides a 1-click Cal.com booking link.
- Fully responsive Telegram
InlineKeyboardMarkupintegration. - Zero client spinner delay via sub-10ms
answerCallbackQueryacknowledgment. - Seamless state transitions whether the user types text or taps an interactive chip.
- Qualified prospects receive a direct
[ π Book Architecture Call ]button. - Automatically encodes name, verified email, and technical project brief as URL query parameters directly into Cal.com or Google Calendar booking widgets.
- Database Storage: Directly inserts into Supabase
inquiriestable with full metadata. - Signed Webhooks: Dispatches outbound
lead.qualifiedevents with HMAC SHA-256 signature (X-Teleflow-Signature) to Zapier, Make, n8n, or custom CRM backends. - Admin Push Alerts: Instantly alerts the operator's personal Telegram chat with direct deep-links to the lead in the command center.
- Edge / Serverless Webhook Mode (Default): Lightweight HTTP listener designed for Vercel Serverless, Cloudflare, Fly.io, or Railway.
- Long-Polling Mode (
--poll): Zero-tunneling local development mode. Automatically cleans old webhooks and polls Telegram directly.
| Metric | Measured Value | Standard / Environment |
|---|---|---|
| Turn Execution Latency | ~284ms | Cold/warm turns on Vercel Node runtime |
| Callback Acknowledgment | < 25ms | Instant spinner dismissal |
| Docker Image Size | < 95MB | Multi-stage Node 22-alpine build |
| Memory Footprint | ~38MB RSS | Zero bloated dependencies; native fetch |
| Test Suite Duration | 159ms | 11 automated assertions, 100% pass |
git clone https://github.com/Sam-CodesAI/teleflow-agent.git
cd teleflow-agent
npm installCopy .env.example to .env:
cp .env.example .envPopulate the required keys:
TELEGRAM_BOT_TOKEN="your_bot_token_from_botfather"
TELEGRAM_ADMIN_CHAT_ID="your_telegram_chat_id"
TELEGRAM_WEBHOOK_SECRET="optional_secret_token"
CAL_BOOKING_URL="https://cal.com/samarth/discovery"Option A β Long Polling Mode (Fastest for local testing, no tunnel needed):
npm run pollOption B β Webhook Server Mode:
npm run dev
# Starts HTTP server listening at http://localhost:3000/webhooknpm test# Build production image
docker build -t teleflow-agent .
# Run container
docker run -d \
-p 3000:3000 \
--name teleflow-agent \
--env-file .env \
teleflow-agentdocker compose up -dCheck health status:
curl http://localhost:3000/health
# {"status":"online","agent":"teleflow-agent","version":"1.2.0"}To register this bot with Telegram's Webhook infrastructure:
curl -F "url=https://your-domain.com/webhook" \
-F "secret_token=your_webhook_secret" \
https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/setWebhookWhen a lead reaches CONFIRMED phase, Teleflow dispatches an outbound event to EXTERNAL_CRM_WEBHOOK_URL:
{
"event": "lead.qualified",
"timestamp": "2026-09-06T06:15:00.000Z",
"payload": {
"name": "Jane Doe",
"email": "jane@techcorp.io",
"contactMethod": "Telegram (@janedoe) / jane@techcorp.io",
"serviceRequested": "Workflow & Business Automation",
"message": "[LEAD INTAKE]\nβ’ Service: Workflow & Business Automation\nβ’ Brief: Sync WhatsApp with HubSpot CRM\nβ’ Timeline: 2β4 weeks"
}
}Samarth Nimangre (Sam)
17-year-old AI Developer & Automation Builder based in Karnataka, India.
- Portfolio: sam-codes.vercel.app
- GitHub: @Sam-CodesAI
- Telegram: @samarth_master_bot / @Samarth1306
- LinkedIn: Samarth Nimangre
- X / Twitter: @Sam_CodeAI
- Instagram: @samarth.buildss
Licensed under the MIT License.