黑帽联盟

标题: TG机器人 删除和查询Webhook 的方法 [打印本页]

作者: 定位    时间: 2023-9-28 19:47
标题: TG机器人 删除和查询Webhook 的方法
前言
找了个根据关键字自动回复机器人,是一个开源项目,有仓库没有任何资料。根据代码反向捣鼓了一番,能用但不好用。期间出现个删除webhook的提示,竟然不知道怎么删。

现象提示
2023/04/12 11:27:18 Conflict: can’t use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first
2023/04/12 11:27:18 Failed to get updates, retrying in 3 seconds…

该机器人之前确实是在别的地方设置过webhook,偷懒没有新申请机器人直接用的,没想到出现了 Conflict 错误。


deleteWebhook 方法
本以为 deleteWebhook 是一个命令,给机器人发命令没反应,没想到就是一个url:
https://api.telegram.org/bot[TOKEN_ID]/setWebhook?url=

[TOKEN_ID] 表示bot完整的 token,拼接完整如:
https://api.telegram.org/bot515687xxxx:XXX0FLLrmAFjp64SViCmNRtc_kmxx-xx-xx/setWebhook?url=

正常情况将返回请求结果:
{"ok":true,"result":true,"description":"Webhook was deleted"}

以上是删除webhook操作


查询webhook绑定的网址是什么操作如下:
https://api.telegram.org/bot[TOKEN_ID]/setWebhook?url=

完整代码如下:
https://api.telegram.org/bot6137xxx878:AAE_XXXXXYoVzXXXXXhWZSQY1vhkJhPh61dKQs/getWebhookinfo


查询结果如下:
{"ok":true,"result":{"url":"https://www.xxxxx.com/api/v1/guest/telegram/webhook?access_token=9d040xxxxxaec30axxxxxdf4498234df","has_custom_certificate":false,"pending_update_count":0,"max_connections":40,"ip_address":"这里是ip地址"}}













欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/) Powered by Discuz! X2.5