Telegram
Source: https://docs.datzi.ai/channels/telegramTelegram (Bot API)
Status: production-ready for bot DMs + groups via grammY. Long polling is the default mode; webhook mode is optional.Quick setup
Create the bot token in BotFather
Open Telegram and chat with @BotFather (confirm the handle is exactly
@BotFather).Run /newbot, follow prompts, and save the token.Telegram side settings
Privacy mode and group visibility
Telegram bots default to Privacy Mode, which limits what group messages they receive. If the bot must see all group messages, either:- disable privacy mode via
/setprivacy, or - make the bot a group admin.
Helpful BotFather toggles
/setjoingroupsto allow/deny group adds/setprivacyfor group visibility behavior
Access control and activation
channels.telegram.dmPolicy controls direct message access:
pairing(default)allowlistopen(requiresallowFromto include"*")disabled
channels.telegram.allowFrom accepts numeric Telegram user IDs. telegram: / tg: prefixes are accepted and normalized.
Finding your Telegram user ID
Safer (no third-party bot):- DM your bot.
- Run
datzi logs --follow. - Read
from.id.
Group policy and allowlists
There are two independent controls:-
Which groups are allowed (
channels.telegram.groups)- no
groupsconfig: all groups allowed groupsconfigured: acts as allowlist (explicit IDs or"*")
- no
-
Which senders are allowed in groups (
channels.telegram.groupPolicy)openallowlist(default)disabled
groupAllowFrom is used for group sender filtering. If not set, Telegram falls back to allowFrom.
Example: allow any member in one specific group:
Mention behavior
Group replies require mention by default. Mention can come from:- native
@botusernamemention, or - mention patterns in:
agents.list[].groupChat.mentionPatternsmessages.groupChat.mentionPatterns
/activation always/activation mention
Runtime behavior
- Telegram is owned by the gateway process.
- Routing is deterministic: Telegram inbound replies back to Telegram.
- Group sessions are isolated by group ID. Forum topics append
:topic:<threadId>to keep topics isolated. - Long polling uses grammY runner with per-chat/per-thread sequencing.
Feature reference
Live stream preview (message edits)
Datzi can stream partial replies by sending a temporary Telegram message and editing it as text arrives.channels.telegram.streaming is off | partial | block | progress (default: off)
Formatting and HTML fallback
Outbound text uses Telegramparse_mode: "HTML".
- Markdown-ish text is rendered to Telegram-safe HTML.
- Raw model HTML is escaped to reduce Telegram parse failures.
- If Telegram rejects parsed HTML, Datzi retries as plain text.
channels.telegram.linkPreview: false.
Native commands and custom commands
Telegram command menu registration is handled at startup withsetMyCommands.
commands.native: "auto" enables native commands for Telegram.
Add custom command menu entries:
Inline buttons
Configure inline keyboard scope:offdmgroupallallowlist(default)
callback_data: <value>
Forum topics and thread behavior
Forum supergroups:- topic session keys append
:topic:<threadId> - replies and typing target the topic thread
- topic config path:
channels.telegram.groups.<chatId>.topics.<threadId>
threadId=1) special-case:
- message sends omit
message_thread_id(Telegram rejectssendMessage(...thread_id=1)) - typing actions still include
message_thread_id
Audio, video, and stickers
Telegram distinguishes voice notes vs audio files.- default: audio file behavior
- tag
[[audio_as_voice]]in agent reply to force voice-note send
Reaction notifications
When enabled, Datzi enqueues system events like:Telegram reaction added: 👍 by Alice (@alice) on msg 42
channels.telegram.reactionNotifications:off | own | all(default:own)channels.telegram.reactionLevel:off | ack | minimal | extensive(default:minimal)
Long polling vs webhook
Default: long polling. Webhook mode:- set
channels.telegram.webhookUrl - set
channels.telegram.webhookSecret(required when webhook URL is set) - optional
channels.telegram.webhookPath(default/telegram-webhook) - optional
channels.telegram.webhookHost(default127.0.0.1)
127.0.0.1:8787.
Troubleshooting
- Bot does not respond to non mention group messages: check privacy mode via BotFather (
/setprivacy-> Disable) and remove + re-add bot. - Bot not seeing group messages at all: when
channels.telegram.groupsexists, group must be listed or include"*". - Commands work partially or not at all: authorize your sender identity;
setMyCommands failedindicates DNS/HTTPS issues toapi.telegram.org. - Polling or network instability: check IPv6 egress if Telegram API calls fail intermittently.
Telegram config reference pointers
channels.telegram.enabled: enable/disable channel startup.channels.telegram.botToken: bot token (BotFather).channels.telegram.dmPolicy:pairing | allowlist | open | disabled(default: pairing).channels.telegram.allowFrom: DM allowlist (numeric Telegram user IDs).channels.telegram.groupPolicy:open | allowlist | disabled(default: allowlist).channels.telegram.groupAllowFrom: group sender allowlist (numeric Telegram user IDs).channels.telegram.groups: per-group defaults + allowlist (use"*"for global defaults).channels.telegram.capabilities.inlineButtons:off | dm | group | all | allowlist(default: allowlist).channels.telegram.replyToMode:off | first | all(default:off).channels.telegram.textChunkLimit: outbound chunk size (chars).channels.telegram.streaming:off | partial | block | progress(live stream preview; default:off).channels.telegram.mediaMaxMb: inbound/outbound media cap (MB).channels.telegram.proxy: proxy URL for Bot API calls (SOCKS/HTTP).channels.telegram.webhookUrl: enable webhook mode.
