Telegram
Send text messages to a Telegram chat by default and enable additional TelegramTools functions explicitly.
TelegramTools exposes send_message by default. Enable media and message-management functions with their enable_* flags, or set all=True to expose every Telegram tool.
Prerequisites
- Create a bot with BotFather.
- Copy the bot token from BotFather.
- Send a message to the bot.
- Get the chat ID from
https://api.telegram.org/bot<your-bot-token>/getUpdates.
from agno.agent import Agent
from agno.tools.telegram import TelegramTools
telegram_token = "<enter-your-bot-token>"
chat_id = "<enter-your-chat-id>"
# TelegramTools exposes only send_message by default.
agent = Agent(
name="telegram-messages",
tools=[TelegramTools(token=telegram_token, chat_id=chat_id)],
description="Send text messages to a Telegram chat.",
instructions=[
"Use send_message to send the requested text.",
"Report whether the message was sent successfully.",
],
markdown=True,
)
if __name__ == "__main__":
agent.print_response("Send 'Hello from Agno!' to the bot")Run the example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U 'agno[telegram]' openaiExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Run the example
Replace telegram_token and chat_id in the code, save it as telegram_tools.py, then run:
python telegram_tools.pyFull source: cookbook/91_tools/telegram_tools.py