Installation
Environment Variables
Create a bot using @BotFather on Telegram to get your bot token.
Configuration Options
Setup
- Auto Mode (Recommended)
- Webhook Mode
- Polling Mode
Adapter automatically chooses webhook or polling based on environment:Auto mode logic:
- If webhook is configured → use webhook mode
- If no webhook and not serverless → use polling mode
- If no webhook and serverless → keep webhook mode (manual setup required)
Webhook Handler
Features
Supported Events
message- Regular messages in chats/groupsedited_message- Edited messageschannel_post- Channel postscallback_query- Inline button clicksmessage_reaction- Reactions added/removed
Message Types
Telegram supports:- Private chats - 1:1 conversations
- Groups - Multi-user chats
- Supergroups - Large groups with threads/topics
- Channels - Broadcast channels
Topic Threads (Supergroups)
For groups with topics enabled:Inline Keyboards (Buttons)
Create messages with inline buttons:Telegram automatically acknowledges button clicks. The adapter calls
answerCallbackQuery for you.Reactions
Add/remove reactions:File Uploads
Send files with messages:Markdown Formatting
Telegram supports markdown in messages:Thread IDs
Telegram thread IDs encode chat ID and optional topic:- Private chat:
telegram:123456789 - Group:
telegram:-987654321 - Group with topic:
telegram:-987654321:42
Chat IDs are negative for groups/supergroups, positive for users.
Opening DMs
Create a private chat with a user:User must have started a conversation with the bot first (via /start command or deep link).
Message History
Message history is cached in-memory:Platform Limits
- Message length: 4,096 characters
- Caption length: 1,024 characters (for files)
- File size: 50 MB (20 MB via Bot API by default, 50 MB with local Bot API server)
- Rate limits: 30 messages/second globally, 1 message/second per chat
- Inline keyboard buttons: 100 buttons max
Code Examples
Polling Control
Manually start/stop polling:Troubleshooting
Webhook verification fails
Webhook verification fails
- Set
secretTokenin adapter config and webhook URL - Verify secret token matches in both places
- Check that header
x-telegram-bot-api-secret-tokenis present
Bot doesn't respond in groups
Bot doesn't respond in groups
- Disable Privacy Mode via @BotFather
- Or add bot as admin to receive all messages
- Groups require
/setprivacydisabled to receive non-command messages
Polling mode conflicts
Polling mode conflicts
- Only one polling instance can run at a time
- Use
telegram.stopPolling()before starting a new instance - Check
telegram.isPollingbefore starting
File uploads fail
File uploads fail
- Verify file size is under 50 MB
- Only one file per message is supported
- Use proper MIME types (optional but recommended)
Bot Commands
Register commands via @BotFather:Next Steps
Message Handling
Process messages and build conversation flows
Inline Keyboards
Create interactive buttons with cards
Telegram Bot API
Learn about Telegram’s Bot API
State Management
Persist data across requests