Install the dependency:
uv pip install 'agno[telegram]'Each Telegram chat gets its own session scope (e.g.,
tg:Telegram Bot:123456789), so conversations stay isolated across chats.Built-in Commands
The Telegram interface registers three commands automatically:| Command | Default Behavior | Customization Parameter |
|---|---|---|
/start | Sends a welcome message | start_message |
/help | Lists supported input types | help_message |
/new | Starts a fresh conversation (requires a database) | new_message |
register_commands=True (default).
Key Features
| Feature | Details |
|---|---|
| Streaming | Edits the response message in real time as tokens arrive. Throttled to ~1 edit/sec for rate limits. Enable with streaming=True (default). |
| Media input | Accepts photos, voice notes, audio, video, video notes, stickers, GIFs, and documents. Media is downloaded and passed to the agent automatically. |
| Media output | Agent tools (e.g., DALL-E, ElevenLabs) can send photos, audio, video, documents, GIFs, and stickers as native Telegram media. |
| Message chunking | Responses longer than 4096 characters are automatically split across multiple messages. |
| Show reasoning | Set show_reasoning=True to surface the model’s reasoning as a blockquote message. |
Local Development Setup
Create a Telegram Bot
- Open Telegram and message @BotFather
- Send
/newbotand follow the prompts to choose a display name and username (username must end inbot, e.g.my_agno_bot) - Copy the bot token (looks like
123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11)
Start a Tunnel with ngrok
Telegram needs a public HTTPS URL to deliver webhook events:Copy the
https:// forwarding URL provided by ngrok and set it as an environment variable:Production Deployment
In production, webhook secret validation is enforced. Telegram sends the secret in theX-Telegram-Bot-Api-Secret-Token header, and the interface rejects requests with an invalid or missing token with a 403.
Group Chat Setup
By default, Telegram bots in groups only receive commands (/start, etc.), @mentions, and replies to their own messages. To allow the bot to read all group messages:
Disable Privacy Mode in BotFather
- Open a chat with @BotFather
- Send
/mybotsand select your bot - Go to Bot Settings → Group Privacy
- Tap Turn off
Re-add the Bot to Existing Groups
Privacy mode changes only apply to groups the bot joins after the change. Remove and re-add the bot to any existing groups. Alternatively, making the bot a group admin bypasses privacy mode entirely.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
403 Forbidden on webhook | Missing or invalid webhook secret | Set TELEGRAM_WEBHOOK_SECRET_TOKEN and register the webhook with a matching secret_token, or set APP_ENV=development for local testing |
| Bot doesn’t respond in groups | Privacy mode enabled | Disable privacy mode in BotFather and re-add the bot to the group |
| Bot doesn’t respond at all | Webhook not registered or server not running | Verify with getWebhookInfo and check that your server is reachable |
| Streaming not working | streaming set to False | Set streaming=True on the Telegram interface (this is the default) |