Development of AI Chatbot with Telegram Integration
Telegram — most popular platform for business chatbots in Russia: 80M+ active users, Bot API with rich features, native file/button/media support.
Telegram Bot API: Capabilities
- Inline Buttons: interactive menus without text input — perfect for option selection
- Webhook vs Polling: Webhook preferred for production (instant messages without polling delay)
- Files: receive and send documents, photos, voice — up to 50MB
- Payments: built-in payment via Stripe, Yookassa, without leaving Telegram
- Mini Apps (WebApp): full React/Vue interface inside Telegram
Tech Stack
# python-telegram-bot v20+ (async)
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import Application, CommandHandler, MessageHandler
async def handle_message(update: Update, context):
user_message = update.message.text
response = await ai_bot.process(user_message, user_id=update.effective_user.id)
keyboard = InlineKeyboardMarkup([
[InlineKeyboardButton("✓ Helpful", callback_data="useful")],
[InlineKeyboardButton("↻ Clarify", callback_data="clarify")],
])
await update.message.reply_text(response, reply_markup=keyboard)
app = Application.builder().token(BOT_TOKEN).build()
app.add_handler(MessageHandler(filters.TEXT, handle_message))
app.run_webhook(webhook_url=WEBHOOK_URL)
Dialog State Management
Telegram doesn't store state — bot's responsibility. ConversationHandler for multi-step flows, Redis for context storage between messages (user_id → conversation_state).
Security
Verify webhook secret token in headers. Rate limiting by user_id. Log all requests. For commercial bots: user verification via phone number (Telegram provides). Deployment: Docker + Nginx on VPS or serverless (Yandex Cloud Functions) with auto-scaling. Latency: Telegram delivers webhook immediately, bot must respond in < 200ms or show "typing...".







