【问题标题】:My bot not reponse back after setup my webhook?我的机器人在设置我的 webhook 后没有回复?
【发布时间】:2021-03-19 17:30:25
【问题描述】:

我被困了一天设置网络挂钩后机器人没有回复我的命令/start

我发誓它在本地使用轮询方法可以正常工作。但设置 web hook 后无法正常工作。我正在使用烧瓶 + heroku

这是我的完整代码:

https://pastebin.com/zBesJBjb

信息:Window 10 Pro x64, 蟒蛇3.8, PythonTelegram 机器人 = 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

【问题讨论】:

    标签: debugging flask heroku python-telegram-bot


    【解决方案1】:

    IISC,您不会在 webhook_handler 的任何地方处理传入的更新。如果您使用dispatcher.start(),则必须调用dispatcher.process_update(update) 或将更新放入调度程序update_queue 以便处理更新。还有两个注意事项:

    • telegram.Update.de_json(request.get_json(force=True), updater) 应改为 telegram.Update.de_json(request.get_json(force=True), updater.bot)
    • 如果您不使用updater 获取更新,则根本不需要它,您只需要Dispatcher

    我建议查看有关webhooks 的 PTB 维基页面。甚至还有一个专用的section on Heroku。诚然,它使用updater.start_webhook,但我并没有在你的代码中看到任何解释你为什么使用flask而不是内置解决方案的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-13
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 2020-11-29
      • 1970-01-01
      • 2017-09-16
      相关资源
      最近更新 更多