返回顶部
t

telegram-openapi-skillTelegram开放API技能

Operate Telegram Bot API through UXC with a curated OpenAPI schema, bot-token path auth, polling-based reads, and webhook management guardrails.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.1
安全检测
已通过
196
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

telegram-openapi-skill

Telegram Bot API 技能

使用此技能通过 uxc + OpenAPI 运行 Telegram Bot API 操作。

复用 uxc 技能以获取共享执行、认证和错误处理指导。

前提条件

  • - uxc 已安装并可在 PATH 中使用。
  • 可访问 https://api.telegram.org 的网络连接。
  • 可访问精选的 OpenAPI 模式 URL:
- https://raw.githubusercontent.com/holon-run/uxc/main/skills/telegram-openapi-skill/references/telegram-bot.openapi.json
  • - 从 BotFather 获取的 Telegram 机器人令牌。

范围

此技能涵盖精简的机器人核心功能:

  • - 机器人身份和聊天查找
  • 文本发送
  • 通过 file_id、HTTP URL 或本地 multipart 上传的媒体发送
  • 通过 getUpdates 轮询
  • Webhook 设置/状态/删除操作

此技能涵盖:

  • - 使用 attach:// 文件数组的 multipart 媒体组
  • 通用 webhook 接收/运行时托管
  • 完整的 Telegram Bot API 功能

认证

Telegram Bot API 需要在请求路径中包含机器人令牌:https://api.telegram.org/bot/METHOD_NAME。

使用请求路径前缀模板配置凭据:

bash
uxc auth credential set telegram-bot \
--auth-type api_key \
--secret-env TELEGRAMBOTTOKEN \
--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/getMe

核心工作流程

  1. 1. 默认使用固定链接命令:
- 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
  1. 2. 首先检查操作模式:
- telegram-openapi-cli get:/getMe -h - telegram-openapi-cli post:/sendMessage -h - telegram-openapi-cli post:/sendPhoto -h - telegram-openapi-cli post:/sendDocument -h - telegram-openapi-cli post:/getUpdates -h
  1. 3. 在写入操作前优先进行读取/设置验证:
- telegram-openapi-cli get:/getMe - telegram-openapi-cli get:/getWebhookInfo - telegram-openapi-cli get:/getChat chatid=@channelorchatid
  1. 4. 使用键/值或位置 JSON 执行操作:
- 键/值: telegram-openapi-cli post:/sendMessage chatid=CHATID text=来自 uxc 的问候 - multipart 上传: telegram-openapi-cli post:/sendPhoto chatid=CHATID photo=/tmp/photo.jpg caption=由 uxc 上传 - 位置 JSON: telegram-openapi-cli post:/sendMessage {chatid:CHATID,text:来自 uxc 的问候} - 守护进程支持的轮询订阅: uxc subscribe start https://api.telegram.org post:/getUpdates {timeout:5,allowedupdates:[message,callbackquery]} --mode poll --poll-config {intervalsecs:2,extractitemspointer:/result,requestcursorarg:offset,cursorfromitempointer:/updateid,cursortransform:increment,checkpointstrategy:{type:itemkey,itemkeypointer:/update_id}} --sink file:/tmp/telegram-updates.ndjson

运行时验证

以下 Telegram 轮询流程已通过 uxc 针对真实 Bot API 验证:

  • - get:/getMe
  • get:/getWebhookInfo
  • 守护进程支持的 uxc subscribe --mode poll 在 post:/getUpdates 上
  • 从 update_id + 1 派生的基于项目的偏移量推进
  • 重复轮询的去重/检查点行为

观察到的运行时行为:

  • - 为真实的 Telegram 更新发出 data 事件
  • poll 事件记录获取/发出/跳过的计数
  • 在发现新更新后发出 checkpoint 事件
  • 重复轮询在检查点推进后跳过已消费的更新

操作组

读取/查找

  • - get:/getMe
  • get:/getChat
  • get:/getChatMember
  • get:/getWebhookInfo

消息发送

  • - post:/sendMessage
  • post:/sendPhoto
  • post:/sendDocument
  • post:/sendMediaGroup

更新投递

  • - post:/getUpdates
  • post:/setWebhook
  • post:/deleteWebhook

防护措施

  • - 保持自动化在 JSON 输出封装上;不要使用 --text。
  • 首先解析稳定字段:ok、kind、protocol、data、error。
  • getUpdates 和 webhook 投递互斥:
- 如果配置了 webhook,在通过 post:/getUpdates 轮询前调用 post:/deleteWebhook - 如果轮询处于活动状态,不要将 webhook 操作视为后台订阅支持
  • - Telegram 每个机器人令牌只允许一个活动的 getUpdates 消费者:
- 如果另一个机器人进程或脚本同时轮询,Telegram 返回 HTTP 409 - 在依赖守护进程支持的轮询订阅前停止其他消费者
  • - 对于守护进程支持的轮询订阅,优先使用基于项目的偏移量推进:
- extractitemspointer 应为 /result - requestcursorarg 应为 offset - cursorfromitempointer 应为 /updateid - cursor_transform 应为 increment - checkpointstrategy.type 通常应为 itemkey,itemkeypointer=/update_id
  • - uxc auth binding match 应针对具体的 Telegram 方法 URL(如 https://api.telegram.org/getMe)进行检查,因为认证通过路径前缀模板应用,该模板扩展为 /bot/...。
  • 此技能中的 sendPhoto、sendDocument 和 sendMediaGroup 仅接受现有的 fileid 值或 HTTP URL;它们不上传新的本地文件。
  • sendPhoto 和 sendDocument 也支持 multipart/form-data 本地文件上传。文件字段必须是本地路径字符串。
  • 此技能中的 sendMediaGroup 仍保持仅 JSON,因为当前的 multipart v1 无法干净地建模 media 数组加 attach:// 文件集。
  • setWebhook 支持通过 certificate 文件字段进行自签名证书的 multipart 证书上传。
  • 将 post:/sendMessage、所有 send* 操作和更改 webhook 的操作视为写入/高风险操作;在执行前需要明确的用户确认。
  • telegram-openapi-cli ... 等同于 uxc https://api.telegram.org --schema-url openapi_schema> ...。

参考资料

  • - 使用模式:references/usage-patterns.md
  • 精选的 OpenAPI 模式:references/telegram-bot.openapi.json
  • Telegram Bot API 文档:https://core.telegram.org/bots/api
  • 本地 Bot API 服务器:https://github.com/tdlib/telegram-bot-api

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 telegram-openapi-skill-1776069903 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 telegram-openapi-skill-1776069903 技能

通过命令行安装

skillhub install telegram-openapi-skill-1776069903

下载

⬇ 下载 telegram-openapi-skill v1.0.1(免费)

文件大小: 7.55 KB | 发布时间: 2026-4-15 14:38

v1.0.1 最新 2026-4-15 14:38
- Add support for `multipart/form-data` local file upload to `sendPhoto` and `sendDocument` (via local path strings).
- Update guardrails: clarify that `sendMediaGroup` is still JSON-only and does not use multipart file arrays.
- Expand documentation for multipart usage, including local photo/document file upload examples.
- `setWebhook` now supports multipart certificate uploads for self-signed certificates through the `certificate` file field.
- Update OpenAPI schema and usage references to reflect multipart and related behavior.
- Improve prerequisites, scope, and operation documentation for clarity.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部