Telegram Reference

Interface parameters, endpoints, and event handling for the Telegram interface.

Interface Parameters

Pass one of agent, team, or workflow to the Telegram constructor.

from agno.os.interfaces.telegram import Telegram

Telegram(agent=my_agent, streaming=True, prefix="/telegram")
ParameterTypeDefaultDescription
agentOptional[Union[Agent, RemoteAgent]]NoneAgno Agent or RemoteAgent instance.
teamOptional[Union[Team, RemoteTeam]]NoneAgno Team or RemoteTeam instance.
workflowOptional[Union[Workflow, RemoteWorkflow]]NoneAgno Workflow or RemoteWorkflow instance.
prefixstr"/telegram"URL prefix for Telegram endpoints (e.g., /telegram/webhook).
tagsOptional[List[str]]["Telegram"]FastAPI route tags for API documentation.
tokenOptional[str]NoneBot token. Falls back to TELEGRAM_TOKEN environment variable.
streamingboolTrueEnable token-by-token streaming with live message edits.
show_reasoningboolFalseSend the model's reasoning as a separate message before the response. Non-streaming mode only.
reply_to_mentions_onlyboolTrueIn groups, respond only to @mentions and replies to the bot. In DMs, always respond.
reply_to_bot_messagesboolTrueRespond when users reply to the bot's own messages in groups.
start_messagestr"Hello! I'm ready..."Message sent for /start command.
help_messagestr"Send me text..."Message sent for /help command.
error_messagestr"Sorry, error..."Message sent when processing fails.
new_messagestr"New conversation..."Message sent for /new command (requires database).
commandsOptional[List[Dict]]See belowBot commands to register. Each dict has command and description keys.
register_commandsboolTrueRegister commands with Telegram Bot API on first message.
quoted_responsesboolFalseBot replies quote the user's message (reply-to behavior).

Default commands:

[
    {"command": "start", "description": "Start the bot"},
    {"command": "help", "description": "Show help"},
    {"command": "new", "description": "Start a new conversation"},
]

Endpoints

POST {prefix}/webhook

Receives Telegram updates (messages, edited messages, media).

StatusResponseDescription
200{"status": "processing"}Message accepted for background processing.
200{"status": "duplicate"}Webhook retry detected (ignored).
200{"status": "ignored"}Not a message event (callback query, etc.).
403ErrorInvalid X-Telegram-Bot-Api-Secret-Token header.
500ErrorProcessing error, or TELEGRAM_WEBHOOK_SECRET_TOKEN not set in production.

GET {prefix}/status

Health check. Returns {"status": "available"}.

Security

Webhook requests must include the X-Telegram-Bot-Api-Secret-Token header, validated against TELEGRAM_WEBHOOK_SECRET_TOKEN using constant-time comparison.

Isolated tests: APP_ENV=development bypasses validation and logs a warning. Keep it unset for public tunnels and deployed webhooks; configure the secret on both the server and setWebhook.

Message Processing

StepBehavior
DeduplicationPer-instance, in-process update_id cache for 60 seconds. This is not durable or shared across replicas.
Bot filteringMessages from other bots ignored.
Group filteringWhen reply_to_mentions_only=True, only process @mentions and replies to the bot.
Command handling/start, /help, /new handled with configurable messages.
Text cleanupBot mentions stripped from message text before passing to agent.
Media processingPhotos, voice, audio, video, documents, stickers, animations downloaded (max 20 MB).

Session Scope

The interface constructs session keys using the chat and optional topic:

Chat TypeSession Scope Format
DMs, basic groupstg:{entity_id}:{chat_id}
Supergroup threads, forum topicstg:{entity_id}:{chat_id}:{message_thread_id}

Current stored-session lookup uses a prefix comparison without a delimiter boundary. For the same user and entity, a scope such as tg:a:12 can select a stored tg:a:123 session. Persistent multi-chat deployments therefore do not yet have strict chat isolation from this lookup. An upstream fix is required before relying on that guarantee.

Streaming Events

When streaming=True, the interface dispatches real-time status updates:

EventDisplay
ReasoningStarted"Reasoning..."
ToolCallStarted"{ToolName}..."
ToolCallCompleted"{ToolName}" (trailing ellipsis removed)
ToolCallError"{ToolName} failed"
RunContentAccumulated content, edited every 1.0s
MemoryUpdateStarted"Updating memory..."

Workflow events: Step names, loop iterations, and parallel execution status shown with indentation.

Rate limiting: Respects Telegram's 429 retry_after field. Pauses edits during rate-limit periods.

Text Formatting

Markdown is converted to Telegram HTML:

MarkdownTelegram HTML
**bold**<b>bold</b>
*italic*<i>italic</i>
__underline__<u>underline</u>
~~strike~~<s>strike</s>
`code`<code>code</code>
```lang\ncode\n```<pre><code class="language-lang">code</code></pre>
> quote<blockquote>quote</blockquote>
[text](url)<a href="url">text</a>
- item• item

Messages exceeding 4096 characters are automatically split.

Media Support

Input (from users):

TypeConverted To
Photos, StickersImage
Voice, AudioAudio
Video, Animation, Video NoteVideo
DocumentsFile

Max download size: 20 MB.

Output (from agent): Images, audio, videos, and files sent via respective Telegram API methods.

Environment Variables

VariableRequiredDescription
TELEGRAM_TOKENYesBot token from @BotFather. Can also pass via token parameter.
TELEGRAM_WEBHOOK_SECRET_TOKENNetwork-reachable webhooksWebhook validation secret. Bypassed when APP_ENV=development.
APP_ENVNoUse development only for isolated non-network tests; it disables webhook verification.

Developer Resources