API
Webhook / 长轮询
setWebhook 与 getUpdates 互斥;本地调试先删 Webhook。
鉴权: Authorization: Bearer sbot_…
POST
Bot Token/api/v1/bots/setWebhooksetWebhook配置 Webhook
使用 Bot Token 直接配置 Webhook;与开发者 JWT 接口二选一。调用后机器人投递模式自动切到 `webhook`。
- 必填:
url(必须 HTTPS) - 强烈建议 / 投递必需:
secret_token(未配置时平台无法签名,Webhook 投递会失败) - 可选:
allowed_updates[]、allowed_ips[]、max_connections(1..100,默认 40)、drop_pending_updates(默认 false) - 返回:
webhook(脱敏)、migrated_update_count、dropped_update_count - 副作用:
Bot.delivery_mode = webhook
POST
Bot Token/api/v1/bots/deleteWebhookdeleteWebhook删除 Webhook
移除当前 Webhook 配置,停止主动 POST 投递;机器人投递模式自动切到 `polling`,可改用 `getUpdates` 拉取。
- 可选:
drop_pending_updates(默认 false;false 时待处理 Update 会迁移到 getUpdates 队列) - 返回:
bot_id/delivery_mode = "polling"/migrated_update_count/dropped_update_count
POST
Bot Token/api/v1/bots/getUpdatesgetUpdatesgetUpdates 长轮询
在 `polling` 模式下拉取等待中的 Update。无公网 IP 也能起 bot;与 webhook 模式互斥(webhook 模式下调用该端点会返回 409)。
- 可选:
offset(拉取update_seq >= offset的条目;推荐用「上一批最后一条 update_seq + 1」做下次 offset,等价 ack) - 可选:
limit(1..100,默认 100) - 可选:
timeout(long-poll 秒数,0 立即返回,最大 50;默认 0) - 可选:
allowed_updates[](如["message","callback_query"],缺省 = 全部) - 返回:
{ updates: [{ update_id, type, message?, callback_query?, update_seq }] } - 冲突:webhook 模式下调用 → 409
Conflict: can't use getUpdates method while webhook is active
GET
Bot Token/api/v1/bots/getWebhookInfogetWebhookInfo查询 Webhook 摘要
返回当前 Webhook 配置摘要 + 平台出站 IP,方便客户在防火墙做白名单。
- 返回:
{ url, has_custom_certificate, pending_update_count, allowed_updates, allowed_ips, last_error_date, last_error_message, last_delivery_at, max_connections, delivery_mode, platform_egress_ips[] } platform_egress_ips为平台出站 IP;delivery_mode为webhook/polling
