skip to Main Content

I am using Telegraf library to work with Telegram API in Node.js and set up a webhook. Okay, now every request that was sent to the bot goes to the route. Now i can work with requests, register users, etc. using MVC structure. Ok, but so what? I could just did the same thing using Telegraf middleware like this.

bot.use(async (ctx, next) => {
  // do anything you need here
  await next()
})

What am i missing? I honestly don’t get it.

2

Answers


  1. as it’s stated in the official documentation

    Setting a webhook means you supplying Telegram with a location in the
    form of a URL, on which your bot listens for updates. We need to be
    able to connect and post updates to that URL.

    Login or Signup to reply.
  2. The difference between them:

    • Long-polling: the bot always asks Telegram API for updates (hence the name).
    • Webhook: Telegram send a POST request to the endpoint you set whenever the bot got update.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search