TelegramTools enable an Agent to send messages to a Telegram chat using the Telegram Bot API.

Prerequisites

pip install -U agno httpx
export TELEGRAM_TOKEN=***

Example

The following agent will send a message to a Telegram chat.

cookbook/tools/tavily_tools.py
from agno.agent import Agent
from agno.tools.telegram import TelegramTools

# How to get the token and chat_id:
# 1. Create a new bot with BotFather on Telegram. https://core.telegram.org/bots/features#creating-a-new-bot
# 2. Get the token from BotFather.
# 3. Send a message to the bot.
# 4. Get the chat_id by going to the URL:
#    https://api.telegram.org/bot/<your-bot-token>/getUpdates

telegram_token = "<enter-your-bot-token>"
chat_id = "<enter-your-chat-id>"

agent = Agent(
    name="telegram",
    tools=[TelegramTools(token=telegram_token, chat_id=chat_id)],
)

agent.print_response("Send message to telegram chat a paragraph about the moon")

Toolkit Params

ParameterTypeDefaultDescription
tokenOptional[str]NoneTelegram Bot API token. If not provided, will check TELEGRAM_TOKEN environment variable.
chat_idUnion[str, int]-The ID of the chat to send messages to.

Toolkit Functions

FunctionDescription
send_messageSends a message to the specified Telegram chat. Takes a message string as input and returns the API response as text. If an error occurs, returns an error message.

Developer Resources