Search code examples
pythontelegramtelegram-bottelebot

Telebot - get message id of message before previous message


I want to create a Telegram questionnaire bot. I use bot.send_message(...) to display a question. A user can then input the answer; the answer is saved, the question is deleted and the next question is shown.

However, a user also has the option using command "/start" to start from the beginning - and that's where the problem occurs: I can easily get the message id of the command itself, but is there a way to get the message id of the message before the command in order to be able to delete it?

For illustration purposes:

Question 1

Answer 1

Question 2

Answer 2

Question 3 <-- (2) but we need this message id

/start

(1) now we are here


Solution

  • but is there a way to get the message id of the message before the command in order to be able to delete it?

    No, the Bot api does not give an option to get the ID of a message before another one.

    The only way is achieving this is to remember the ID yourself