【问题标题】:Telegram Bot getUpdates VS setWebhook电报机器人 getUpdates VS setWebhook
【发布时间】:2017-02-23 07:04:33
【问题描述】:

我想为企业开发机器人! 我不知道使用getUpdates 方法开发Windows 桌面应用程序并在vps 上运行它(https://github.com/MrRoundRobin/telegram.bot 库) 或者使用setWebhook的方法用php开发bot!

在速度等方面哪个更好? 还有哪些其他区别?

【问题讨论】:

    标签: telegram telegram-bot


    【解决方案1】:

    您想使用哪种服务器端应用程序并不重要。 通常getUpdates 用于调试。要发布您的机器人,您需要使用WebhookSee this.

    getUpdates 是拉机制,setWebhook 是推机制。 与 getUpdates 相比,使用 Webhook 有一些优势:

    1. 避免您的机器人不得不频繁请求更新。
    2. 避免在您的代码中使用某种轮询机制。

    【讨论】:

      【解决方案2】:

      一个受欢迎的库 python-telegram-bot 围绕通过 getUpdates 进行轮询构建了大多数示例,然后谨慎地转向 webhook:

      您应该有充分的理由从轮询切换到 webhook。

      https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks

      我个人的看法是,webhook 是一种从 Telegram API 接收事件信息的更简洁的方式(POST 请求在事件发生后立即从 Telegram 发出,不需要空闲循环),但它需要更多的基础设施:

      • 公开一个公共 API 端点
      • 应用程序必须准备好处理对端点的调用

      大多数教程都关注如何让机器人示例快速运行并在本地机器上完成,因此getUpdates 是一个自然的选择。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-08
        • 1970-01-01
        • 2017-08-18
        • 1970-01-01
        • 2016-03-09
        • 2016-01-30
        • 2018-01-10
        • 2018-07-22
        相关资源
        最近更新 更多