Install the Telegram dependency:
pip install 'agno[telegram]'In DMs, each chat gets its own session. In group chats, sessions are scoped by reply thread so each conversation maintains its own context.
Setup and Configuration
Create a Telegram Bot
- Open Telegram and search for @BotFather
- Send
/newbot - Follow the prompts to choose a name and username for your bot
- BotFather will respond with your bot token (looks like
123456789:ABCdefGHIjklMNOpqrsTUVwxyz) - Save this token securely
Setup Environment Variables
Create a For development, also set:This bypasses webhook secret validation for local testing.
.env file in your project root:Setup Webhook with ngrok
- Run ngrok to expose your local server:
- Copy the
https://URL provided by ngrok - Set the webhook by running:
- Verify the webhook is set:
Configure for Production
For production deployments, set a webhook secret for request validation:Set the webhook with the secret token:
Configure Bot Settings (Optional)
Use BotFather to customize your bot:
/setdescription- Set the bot’s description/setabouttext- Set the “About” text/setuserpic- Set the bot’s profile picture/setcommands- Set the command menu (e.g.,/start,/help)
- Send
/mybotsto BotFather - Select your bot
- Go to “Bot Settings” > “Group Privacy”
- Disable privacy mode
ngrok is used only for local development and testing. For production deployments, see the deployment tutorials.