debugging - 我的机器人在设置我的 webhook 后没有回复?
问题描述
我被困了一天/start
设置网络挂钩后机器人没有响应我的命令。
我发誓它在本地使用轮询方法可以正常工作。但设置 web hook 后无法正常工作。我正在使用烧瓶 + heroku
这是我的完整代码:
信息:Window 10 Pro x64,Python 3.8,PythonTelegram Bot = 13.4.1
我的 WebhookInfo 响应:
{
"ok": true,
"result": {
"url": "https://hello-world.herokuapp.com/xxxx",
"has_custom_certificate": false,
"pending_update_count": 0,
"max_connections": 40,
"ip_address": "54.165.0.49"
}
}
部署到heroku后我的日志: https ://pastebin.com/sFD403LU
解决方案
IISC,您不会在webhook_handler
. 如果您使用为了处理更新,您必须调用dispatcher.process_update(update)
或将更新放入调度程序。还有两个注意事项:update_queue
dispatcher.start()
telegram.Update.de_json(request.get_json(force=True), updater)
应该改为telegram.Update.de_json(request.get_json(force=True), updater.bot)
- 如果你不使用
updater
获取更新,你根本不需要它,你只需要一个Dispatcher
我建议查看 PTBs wiki page about webhooks。Heroku甚至还有专门的部分。诚然,它使用updater.start_webhook
,但我并没有在你的代码中看到任何解释你为什么使用烧瓶而不是内置解决方案的东西。