Documentation Sync
This page is auto-generated from plugins/adapters/telegram/README.md. Please edit the in-package README and then run pnpm sync:adapter-docs.
@zhin.js/adapter-telegram
Zhin.js Telegram Bot API adapter (Plugin Runtime). By default, it sends and receives messages via long polling getUpdates (no host required).
Features
- Long polling
getUpdatesinbound (default; no public IP / host-http required) - Parses text / image / video / audio / voice / document / sticker / location / callback_query
- Supports private chat and groups
- Outbound
send({ target, payload })-> Bot API (text / media / keyboard) - Convention-based
defineAdapter/definePlugin(nousePluginneeded) - Webhook mode deferred (requires
httpHostToken); configuringpolling: falsewill produce an explicit error
Installation
pnpm add @zhin.js/adapter-telegramPlugin Runtime
@zhin.js/adapter— convention-basedadapters/telegram.ts(defineAdapter)@zhin.js/core—messageGatewayTokeninbound/outbound@zhin.js/plugin-runtime—plugin.ts(definePlugin)- Configuration goes to
plugins.<instanceKey>via the plugin'sschema.json - Does not require
@zhin.js/host-http(polling path)
Inbound: gateway.receive({ adapter, target: chatId, content: text, sender, metadata }) Outbound: send({ target, payload }) -> Telegram Bot API
Platform Permissions (platform permit)
- Sender role has been restored: for group messages, inbound uses
getChatMember(60s cache) to resolve the sender, writing tometadata.senderRole/metadata.senderPermissions. plugin.tsregisters a checker during generation setup and unregisters on dispose; Plugin Runtime CapabilityIngress and ToolSystem uniformly consumepermissionsvia Core'scanAccessTool().
Prerequisites
| Requirement | Description |
|---|---|
| Bot Token | Create and obtain a Token via @BotFather |
| Polling (default) | Works for both local and production; actively pulls updates, no public HTTPS needed |
| Network | Outbound must be able to reach api.telegram.org |
| host-http | Not needed for Polling; Webhook deferred to next milestone |
Required fields (endpoints[i]): name, token.
Minimal Configuration
# zhin.config.yml (Plugin Runtime)
plugins:
telegram:
# polling: true # default
endpoints:
- name: my-telegram-bot
token: ${TELEGRAM_TOKEN}The root plugin zhin.plugins (or project graph) must reference @zhin.js/adapter-telegram (instanceKey: telegram).
Environment Variables
| Variable | Description |
|---|---|
TELEGRAM_TOKEN / TELEGRAM_BOT_TOKEN | Bot Token |
TELEGRAM_BOT_NAME | Optional, default endpoint name |
Webhook (deferred)
polling: false + webhook currently throws an explicit error:
Telegram webhook mode is deferred until httpHostToken wiring; use polling: true (default) for now
The next milestone will register a POST route via httpHostToken, instead of using Telegraf's self-hosted listener or the legacy host-router.
Message Type Mapping
| Telegram | Inbound content (text summary) | Outbound wire |
|---|---|---|
| text | Original text | sendMessage |
| photo | [image] / caption | sendPhoto (file_id / url) |
| video | [video] | sendVideo |
| audio / voice | [audio] / [voice] | sendAudio / sendVoice |
| document | [file: name] | sendDocument |
| sticker | [sticker: ...] | sendSticker |
| location | [location: lat,lon] | sendLocation |
| callback_query | [action: data] | — |
AI Tools
| Kind | Path |
|---|---|
| Platform tools (10) | agent/tools/ (invite / pin / admins / sticker / poll, etc.) |
| Skill doc | agent/skills/telegram.md |
Troubleshooting
| Symptom | Investigation |
|---|---|
| Not receiving messages | Check if the token is correct; ensure the process has called open(); do not run multiple processes polling with the same token |
| Polling errors | Check if api.telegram.org is reachable; review logs for op: poll |
| Webhook configuration error | Only polling is currently supported; remove polling: false |
| Send failure | Check if the token has been revoked; review the Bot API error description |
Documentation
License
MIT