telegram-openapi-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTelegram Bot API Skill
Telegram Bot API 技能
Use this skill to run Telegram Bot API operations through + OpenAPI.
uxcReuse the skill for shared execution, auth, and error-handling guidance.
uxc使用本技能可通过 + OpenAPI执行Telegram Bot API操作。
uxc复用技能以实现共享执行、认证和错误处理指引。
uxcPrerequisites
前置条件
- is installed and available in
uxc.PATH - Network access to .
https://api.telegram.org - Access to the curated OpenAPI schema URL:
https://raw.githubusercontent.com/holon-run/uxc/main/skills/telegram-openapi-skill/references/telegram-bot.openapi.json
- A Telegram bot token from BotFather.
- 已安装且可在
uxc中访问。PATH - 可访问的网络权限。
https://api.telegram.org - 可访问精选OpenAPI Schema的URL:
https://raw.githubusercontent.com/holon-run/uxc/main/skills/telegram-openapi-skill/references/telegram-bot.openapi.json
- 从BotFather获取的Telegram机器人令牌。
Scope
适用范围
This skill covers a lean bot core surface:
- bot identity and chat lookup
- text sends
- media sends by , HTTP URL, or local multipart upload
file_id - polling via
getUpdates - webhook setup/status/delete operations
This skill does not cover:
- multipart media groups with file arrays
attach:// - generic webhook ingestion/runtime hosting
- the full Telegram Bot API surface
本技能覆盖精简的机器人核心功能:
- 机器人身份与聊天查询
- 文本消息发送
- 通过、HTTP URL或本地多部分上传发送媒体
file_id - 通过进行轮询
getUpdates - Webhook的设置/状态查询/删除操作
本技能不包含以下内容:
- 使用文件数组的多部分媒体组
attach:// - 通用Webhook接收/运行时托管
- 完整的Telegram Bot API功能
Authentication
认证
Telegram Bot API requires the bot token in the request path: .
https://api.telegram.org/bot<TOKEN>/METHOD_NAMEConfigure the credential with a request path prefix template:
bash
uxc auth credential set telegram-bot \
--auth-type api_key \
--secret-env TELEGRAM_BOT_TOKEN \
--path-prefix-template "/bot{{secret}}"
uxc auth binding add \
--id telegram-bot \
--host api.telegram.org \
--scheme https \
--credential telegram-bot \
--priority 100Validate the local mapping when auth looks wrong:
bash
uxc auth binding match https://api.telegram.org/getMeTelegram Bot API要求在请求路径中包含机器人令牌:。
https://api.telegram.org/bot<TOKEN>/METHOD_NAME使用请求路径前缀模板配置凭据:
bash
uxc auth credential set telegram-bot \
--auth-type api_key \
--secret-env TELEGRAM_BOT_TOKEN \
--path-prefix-template "/bot{{secret}}"
uxc auth binding add \
--id telegram-bot \
--host api.telegram.org \
--scheme https \
--credential telegram-bot \
--priority 100当认证出现问题时,验证本地映射:
bash
uxc auth binding match https://api.telegram.org/getMeCore Workflow
核心工作流程
-
Use the fixed link command by default:
command -v telegram-openapi-cli- If missing, create it:
uxc link telegram-openapi-cli https://api.telegram.org --schema-url https://raw.githubusercontent.com/holon-run/uxc/main/skills/telegram-openapi-skill/references/telegram-bot.openapi.json telegram-openapi-cli -h
-
Inspect operation schema first:
telegram-openapi-cli get:/getMe -htelegram-openapi-cli post:/sendMessage -htelegram-openapi-cli post:/sendPhoto -htelegram-openapi-cli post:/sendDocument -htelegram-openapi-cli post:/getUpdates -h
-
Prefer read/setup validation before writes:
telegram-openapi-cli get:/getMetelegram-openapi-cli get:/getWebhookInfotelegram-openapi-cli get:/getChat chat_id=@channel_or_chat_id
-
Execute operations with key/value or positional JSON:
- key/value:
telegram-openapi-cli post:/sendMessage chat_id=CHAT_ID text="Hello from uxc" - multipart upload:
telegram-openapi-cli post:/sendPhoto chat_id=CHAT_ID photo=/tmp/photo.jpg caption="Uploaded by uxc" - positional JSON:
telegram-openapi-cli post:/sendMessage '{"chat_id":"CHAT_ID","text":"Hello from uxc"}' - daemon-backed polling subscribe:
uxc subscribe start https://api.telegram.org post:/getUpdates '{"timeout":5,"allowed_updates":["message","callback_query"]}' --mode poll --poll-config '{"interval_secs":2,"extract_items_pointer":"/result","request_cursor_arg":"offset","cursor_from_item_pointer":"/update_id","cursor_transform":"increment","checkpoint_strategy":{"type":"item_key","item_key_pointer":"/update_id"}}' --sink file:/tmp/telegram-updates.ndjson
- key/value:
-
默认使用固定链接命令:
command -v telegram-openapi-cli- 若命令不存在,创建链接:
uxc link telegram-openapi-cli https://api.telegram.org --schema-url https://raw.githubusercontent.com/holon-run/uxc/main/skills/telegram-openapi-skill/references/telegram-bot.openapi.json telegram-openapi-cli -h
-
先查看操作Schema:
telegram-openapi-cli get:/getMe -htelegram-openapi-cli post:/sendMessage -htelegram-openapi-cli post:/sendPhoto -htelegram-openapi-cli post:/sendDocument -htelegram-openapi-cli post:/getUpdates -h
-
在执行写入操作前优先进行读取/设置验证:
telegram-openapi-cli get:/getMetelegram-openapi-cli get:/getWebhookInfotelegram-openapi-cli get:/getChat chat_id=@channel_or_chat_id
-
使用键值对或位置JSON执行操作:
- 键值对方式:
telegram-openapi-cli post:/sendMessage chat_id=CHAT_ID text="Hello from uxc" - 多部分上传方式:
telegram-openapi-cli post:/sendPhoto chat_id=CHAT_ID photo=/tmp/photo.jpg caption="Uploaded by uxc" - 位置JSON方式:
telegram-openapi-cli post:/sendMessage '{"chat_id":"CHAT_ID","text":"Hello from uxc"}' - 守护进程支持的轮询订阅:
uxc subscribe start https://api.telegram.org post:/getUpdates '{"timeout":5,"allowed_updates":["message","callback_query"]}' --mode poll --poll-config '{"interval_secs":2,"extract_items_pointer":"/result","request_cursor_arg":"offset","cursor_from_item_pointer":"/update_id","cursor_transform":"increment","checkpoint_strategy":{"type":"item_key","item_key_pointer":"/update_id"}}' --sink file:/tmp/telegram-updates.ndjson
- 键值对方式:
Runtime Validation
运行时验证
The following Telegram polling flow has been validated against the real Bot API through :
uxcget:/getMeget:/getWebhookInfo- daemon-backed on
uxc subscribe --mode pollpost:/getUpdates - item-derived offset progression from
update_id + 1 - dedupe/checkpoint behavior for repeated polls
Observed runtime behavior:
- events are emitted for real Telegram updates
data - events record fetched/emitted/skipped counts
poll - events are emitted after new updates are seen
checkpoint - repeated polls skip already-consumed updates after checkpoint advancement
以下Telegram轮询流程已通过在真实Bot API上验证:
uxcget:/getMeget:/getWebhookInfo- 基于守护进程的调用
uxc subscribe --mode pollpost:/getUpdates - 从派生的偏移量递进
update_id + 1 - 重复轮询的去重/检查点行为
观察到的运行时行为:
- 针对真实Telegram更新触发事件
data - 事件记录获取/触发/跳过的数量
poll - 发现新更新后触发事件
checkpoint - 检查点推进后,重复轮询会跳过已消费的更新
Operation Groups
操作分组
Read / Lookup
读取/查询
get:/getMeget:/getChatget:/getChatMemberget:/getWebhookInfo
get:/getMeget:/getChatget:/getChatMemberget:/getWebhookInfo
Messaging
消息发送
post:/sendMessagepost:/sendPhotopost:/sendDocumentpost:/sendMediaGroup
post:/sendMessagepost:/sendPhotopost:/sendDocumentpost:/sendMediaGroup
Update Delivery
更新交付
post:/getUpdatespost:/setWebhookpost:/deleteWebhook
post:/getUpdatespost:/setWebhookpost:/deleteWebhook
Guardrails
防护措施
- Keep automation on the JSON output envelope; do not use .
--text - Parse stable fields first: ,
ok,kind,protocol,data.error - and webhook delivery are mutually exclusive:
getUpdates- if a webhook is configured, call before polling with
post:/deleteWebhookpost:/getUpdates - if polling is active, do not treat webhook operations as background subscription support
- if a webhook is configured, call
- Telegram allows only one active consumer per bot token:
getUpdates- if another bot process or script is polling at the same time, Telegram returns HTTP 409
- stop the other consumer before relying on daemon-backed polling subscribe
- For daemon-backed polling subscribe, prefer item-derived offset progression:
- should be
extract_items_pointer/result - should be
request_cursor_argoffset - should be
cursor_from_item_pointer/update_id - should be
cursor_transformincrement - should usually be
checkpoint_strategy.typewithitem_keyitem_key_pointer=/update_id
- should be checked against a concrete Telegram method URL such as
uxc auth binding match, because auth is applied through a path-prefix template that expands tohttps://api.telegram.org/getMe./bot<TOKEN>/... - ,
sendPhoto, andsendDocumentin this skill accept existingsendMediaGroupvalues or HTTP URLs only; they do not upload new local files.file_id - and
sendPhotoalso supportsendDocumentlocal file uploads. File fields must be local path strings.multipart/form-data - still stays JSON-only in this skill because current multipart v1 does not model the
sendMediaGrouparray plusmediafile set cleanly.attach:// - supports multipart certificate upload for self-signed certs through the
setWebhookfile field.certificate - Treat , all
post:/sendMessageoperations, and webhook-changing operations as write/high-risk actions; require explicit user confirmation before execution.send* - is equivalent to
telegram-openapi-cli <operation> ....uxc https://api.telegram.org --schema-url <telegram_openapi_schema> <operation> ...
- 仅在JSON输出包上进行自动化操作,请勿使用参数。
--text - 优先解析稳定字段:、
ok、kind、protocol、data。error - 与Webhook交付互斥:
getUpdates- 若已配置Webhook,在使用进行轮询前需调用
post:/getUpdatespost:/deleteWebhook - 若轮询处于活跃状态,请勿将Webhook操作视为后台订阅支持
- 若已配置Webhook,在使用
- Telegram每个机器人令牌仅允许一个活跃的消费者:
getUpdates- 若其他机器人进程或脚本同时进行轮询,Telegram会返回HTTP 409
- 在依赖守护进程支持的轮询订阅前,请停止其他消费者
- 对于守护进程支持的轮询订阅,优先使用基于项的偏移量递进:
- 应设为
extract_items_pointer/result - 应设为
request_cursor_argoffset - 应设为
cursor_from_item_pointer/update_id - 应设为
cursor_transformincrement - 通常应设为
checkpoint_strategy.type,且item_keyitem_key_pointer=/update_id
- 应针对具体的Telegram方法URL(如)检查
https://api.telegram.org/getMe,因为认证是通过路径前缀模板扩展为uxc auth binding match来应用的。/bot<TOKEN>/... - 本技能中的、
sendPhoto和sendDocument仅接受已有的sendMediaGroup值或HTTP URL;不支持上传新的本地文件。file_id - 和
sendPhoto也支持sendDocument本地文件上传。文件字段必须为本地路径字符串。multipart/form-data - 本技能中的仍仅支持JSON格式,因为当前的多部分v1版本无法清晰地建模
sendMediaGroup数组加上media文件集合。attach:// - 支持通过
setWebhook文件字段上传自签名证书的多部分上传。certificate - 将、所有
post:/sendMessage操作以及更改Webhook的操作视为写入/高风险操作;执行前需获取用户明确确认。send* - 等价于
telegram-openapi-cli <operation> ...。uxc https://api.telegram.org --schema-url <telegram_openapi_schema> <operation> ...
References
参考资料
- Usage patterns:
references/usage-patterns.md - Curated OpenAPI schema:
references/telegram-bot.openapi.json - Telegram Bot API docs: https://core.telegram.org/bots/api
- Local Bot API server: https://github.com/tdlib/telegram-bot-api
- 使用模式:
references/usage-patterns.md - 精选OpenAPI Schema:
references/telegram-bot.openapi.json - Telegram Bot API文档:https://core.telegram.org/bots/api
- 本地Bot API服务器:https://github.com/tdlib/telegram-bot-api