Telegram Bot getUpdates VS setWebhook
Asked Answered
H

2

7

I want to develop a bot for a business! I don't know that using getUpdates method for develop a windows desktop application and run that on vps (by https://github.com/MrRoundRobin/telegram.bot library) or using setWebhook method to develop bot with php!

Which one is better in terms of speed and etc? And what are some other differences?

Houck answered 14/10, 2016 at 0:33 Comment(0)
L
6

It does not matter you want to use which kind of server side applications. Typically getUpdates used for debugging. For publishing your bots, you need to using the Webhook. See this.

getUpdates is a pull mechanism, setWebhook is push. There are some advantages of using a Webhook over getUpdates:

  1. Avoids your bot having to ask for updates frequently.
  2. Avoids the need for some kind of polling mechanism in your code.
Logician answered 14/10, 2016 at 6:44 Comment(0)
D
3

A popular library python-telegram-bot builds most examples around polling through getUpdates and later moves on to webhooks, cautiously:

You should have a good reason to switch from polling to a webhook.

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

My personal take is that webhook is a cleaner way to receive event information form Telegram API (POST request goes from Telegram right after after the event, no need for idle looping), but it needs more infrastructure:

  • expose a public API endpoint
  • application must be ready to porcess this call to an endpoint

Most tutorials focus on how to get a bot example running quickly and do that on a local machine, so getUpdates is a natural choice for this.

Dystrophy answered 2/5, 2020 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.