如何删除 Telegram 机器人 Webhook
删除 Webhook 可以让机器人切回长轮询(getUpdates)、迁移到其他服务器,或阻止失效的地址继续积压更新。
几次点击即可完成——无需写代码、无需服务器,直接在浏览器中操作。
打开 Webhook 管理器什么时候需要
- 你在本地用基于 getUpdates 的库运行机器人,看到
409 Conflict: can't use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first。 - 你要把机器人迁移到其他服务器或域名。
- 旧地址已经不存在,但 Telegram 仍在重试。
在线删除 Webhook
- 使用 Token 连接机器人。
- 打开 Webhook → 危险操作。
- 如果不需要队列中的更新,勾选丢弃待处理更新。
- 点击删除 Webhook 并确认。
使用 curl
curl -X POST "https://api.telegram.org/bot$BOT_TOKEN/deleteWebhook" \
--form-string "drop_pending_updates=true"然后通过长轮询接收更新:
curl "https://api.telegram.org/bot$BOT_TOKEN/getUpdates?timeout=30"只清空队列
如果只想丢弃卡住的更新而保留 Webhook,请使用丢弃待处理更新:它会用相同的 URL 和 drop_pending_updates=true 再次调用 setWebhook。请输入 Secret Token 以保留它。
注意
deleteWebhook不会影响命令、资料或其他设置。- 如果不使用
drop_pending_updates,队列中的更新(最多保留 24 小时)会在之后的 getUpdates 调用中返回。
几次点击即可完成——无需写代码、无需服务器,直接在浏览器中操作。
打开 Webhook 管理器