电报机器人 getUpdates VS setWebhook
Telegram Bot getUpdates VS setWebhook
我想为企业开发一个机器人!
我不知道使用 getUpdates method for develop a windows desktop application and run that on vps (by https://github.com/MrRoundRobin/telegram.bot 库)
或使用 setWebhook 方法开发带有 php!
的机器人
哪个在速度等方面更好?
还有哪些其他区别?
您要使用哪种服务器端应用程序并不重要。
通常 getUpdates
用于调试。要发布您的机器人,您需要使用 Webhook
。 See this.
getUpdates is a pull mechanism, setWebhook is push.
There are some advantages of using a Webhook over getUpdates:
- Avoids your bot having to ask for updates frequently.
- Avoids the need for some kind of polling mechanism in your code.
一个流行的库 python-telegram-bot
通过 getUpdates
围绕轮询构建大多数示例,然后谨慎地转向 webhooks:
You should have a good reason to switch from polling to a webhook.
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks
我个人的看法是,webhook 是一种从 Telegram API 接收事件信息的更简洁的方式(POST 请求在事件发生后立即从 Telegram 发出,不需要空闲循环),但是它需要更多基础设施:
- 公开一个 public API 端点
- 应用程序必须准备好处理对端点的调用
大多数教程都关注如何快速获取机器人示例 运行 并在本地计算机上执行此操作,因此 getUpdates
是自然而然的选择。
我想为企业开发一个机器人! 我不知道使用 getUpdates method for develop a windows desktop application and run that on vps (by https://github.com/MrRoundRobin/telegram.bot 库) 或使用 setWebhook 方法开发带有 php!
的机器人哪个在速度等方面更好? 还有哪些其他区别?
您要使用哪种服务器端应用程序并不重要。
通常 getUpdates
用于调试。要发布您的机器人,您需要使用 Webhook
。 See this.
getUpdates is a pull mechanism, setWebhook is push. There are some advantages of using a Webhook over getUpdates:
- Avoids your bot having to ask for updates frequently.
- Avoids the need for some kind of polling mechanism in your code.
一个流行的库 python-telegram-bot
通过 getUpdates
围绕轮询构建大多数示例,然后谨慎地转向 webhooks:
You should have a good reason to switch from polling to a webhook.
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks
我个人的看法是,webhook 是一种从 Telegram API 接收事件信息的更简洁的方式(POST 请求在事件发生后立即从 Telegram 发出,不需要空闲循环),但是它需要更多基础设施:
- 公开一个 public API 端点
- 应用程序必须准备好处理对端点的调用
大多数教程都关注如何快速获取机器人示例 运行 并在本地计算机上执行此操作,因此 getUpdates
是自然而然的选择。