先决条件
示例
下面的代理将向 Telegram 聊天发送消息。cookbook/tools/tavily_tools.py
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
pip install -U agno httpx
export TELEGRAM_TOKEN=***
from agno.agent import Agent
from agno.tools.telegram import TelegramTools
# 如何获取 token 和 chat_id:
# 1. 在 Telegram 上使用 BotFather 创建一个新机器人。https://core.telegram.org/bots/features#creating-a-new-bot
# 2. 从 BotFather 获取 token。
# 3. 向机器人发送消息。
# 4. 通过访问以下 URL 获取 chat_id:
# 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("向 Telegram 聊天发送一段关于月球的文字")
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
token | Optional[str] | None | Telegram Bot API token。如果未提供,将检查 TELEGRAM_TOKEN 环境变量。 |
chat_id | Union[str, int] | - | 要发送消息的聊天 ID。 |
| 函数 | 描述 |
|---|---|
send_message | 向指定的 Telegram 聊天发送消息。接受消息字符串作为输入,并以文本形式返回 API 响应。如果发生错误,则返回错误消息。 |