Core Components
TelegramInterface– Wraps an UpsonicAgentfor Telegram via FastAPI and Telegram Bot API.TelegramTools– Used internally for sending messages, files, chat actions, and webhook management.InterfaceManager.serve– Serves the FastAPI app (e.g. Uvicorn).
Initialization Parameters
Key Methods
Full Configuration Example
Human-in-the-Loop (HITL) Confirmation
Tools decorated with@tool(requires_confirmation=True) pause the run until the user confirms or rejects in Telegram. The interface sends a message with inline Confirm / Reject buttons; callbacks are handled automatically. Works in both TASK and CHAT modes.
Streaming
Setstream=True to progressively edit the Telegram message as tokens arrive from the agent. An initial message is sent immediately and then updated in-place as new chunks are generated. Updates are throttled to ~1 second intervals to respect Telegram rate limits. Works in both TASK and CHAT modes.
Heartbeat
When used with anAutonomousAgent that has heartbeat=True, the interface periodically sends the agent’s heartbeat_message to the agent, then delivers the response to the Telegram chat.
The target chat ID is resolved automatically from the first incoming message. You can also set it explicitly via heartbeat_chat_id.
Endpoints
All endpoints are mounted under the/telegram prefix.
POST /telegram/webhook
- Receives Telegram updates (messages, edited messages, channel posts, callback queries).
- Validates
X-Telegram-Bot-Api-Secret-Tokenifwebhook_secretis set. - Processes updates in the background; responds with
200 {"ok": true}so Telegram does not retry.
POST /telegram/set-webhook
- Sets the bot webhook URL.
- Query:
url(required),secret_token(optional),drop_pending_updates(optional, defaultFalse). - Returns
{"success": bool}.
TELEGRAM_WEBHOOK_URL, you can register the webhook manually after starting the server:
POST /telegram/delete-webhook
- Removes the current webhook.
- Query:
drop_pending_updates(optional). - Returns
{"success": bool}.
GET /telegram/webhook-info
- Returns current webhook status from Telegram (e.g. URL, pending update count).
GET /telegram/health
- Health and status of the interface: bot connectivity, configuration (mode, whitelist, parse_mode, behavior flags), and optional bot info from Telegram.

