Skip to main content
This example creates a simple agent for answering questions on Telegram:
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: Commands are registered with the Telegram Bot API on first message when register_commands=True (default).

Key Features

Local Development Setup

1

Prerequisites

Ensure you have the following:
  • A Telegram account
  • ngrok (for development)
  • Python 3.7+
2

Create a Telegram Bot

  1. Open Telegram and message @BotFather
  2. Send /newbot and follow the prompts to choose a display name and username (username must end in bot, e.g. my_agno_bot)
  3. Copy the bot token (looks like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11)
3

Set Environment Variables

4

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:
5

Run the App

The server starts on http://localhost:7777.
6

Register the Webhook

Tell Telegram to send updates to your tunnel URL:
You should see {"ok":true,"result":true,"description":"Webhook was set"}.Verify anytime with:

Production Deployment

In production, webhook secret validation is enforced. Telegram sends the secret in the X-Telegram-Bot-Api-Secret-Token header, and the interface rejects requests with an invalid or missing token with a 403.
1

Set the Webhook Secret

Generate a secret and set it as an environment variable:
2

Register the Webhook with the Secret

Pass the secret_token parameter when registering your webhook:
3

Remove APP_ENV=development

Do not set APP_ENV=development in production. Without it, webhook secret validation is active.

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:
1

Disable Privacy Mode in BotFather

  1. Open a chat with @BotFather
  2. Send /mybots and select your bot
  3. Go to Bot SettingsGroup Privacy
  4. Tap Turn off
BotFather confirms: “Privacy mode is disabled for YourBot.”
2

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.
3

Configure Reply Behavior

Control whether the bot responds to every message or only mentions:
Set reply_to_mentions_only=False to respond to all messages in the group.

Troubleshooting

Developer Resources