0

I'm developing a Telegram bot using Node.js and node-telegram-bot-api library. I want to get the id of the previous message in the chat. How can I achieve this?

I tried using this https://api.telegram.org/botХХХХ:ХХХХХХ/getUpdates?offset=-1 but it gives the following error message:

{"ok":false,"error_code":409,"description":"Conflict: can't use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first"}
Dummy Cron
  • 143
  • 2
  • 11

1 Answers1

0

As per Telegram docs:

There are two mutually exclusive ways of receiving updates for your bot - the getUpdates method on one hand and webhooks on the other.

Later, in the description of getUpdates method:

This method will not work if an outgoing webhook is set up.

Basically, there are two methods of how to receive updates (messages, new users etc.) of your Telegram bot. One is via getUpdates method - when using this method, you should run getUpdates method regularly to receive all the new updates.

The second method is via webhook - you set up a url where Telegram will send a request whenever your bot receives an Update. In most cases this is a more practical way to receive Updates, albeit a bit harder to implement.

These two methods are mutually exclusive - if you have webhook set up, you can't use getUpdates method. The solution, if you want to use getUpdates method, is to delete the webhook with the deleteWebhook method.

druskacik
  • 2,176
  • 2
  • 13
  • 26
  • Thank you for the explanation, I'm using Webhooks as I have deployed my bot on a server, is there a way to get the id of the previous message? – Dummy Cron Jul 01 '22 at 08:01
  • Unfortunately no, if you didn't save the `Update` with the message somewhere. Good idea is to always save the `Update` objects in a database if you want to work with them later. – druskacik Jul 01 '22 at 08:48