A
A
Alexander Ivanov2020-08-14 10:59:44
Bots
Alexander Ivanov, 2020-08-14 10:59:44

What should be the logic of the telegram bot?

I am writing a telegram bot, in which there is a chain of questions to the user. As a result, it should turn out so that it would be possible to process several users at the same time. To do this, I decided to store data about the current state of the user in the database, i.e. at what stage it is now, so that it would be possible to continue at any time, even if the user paused. When a new message from the user enters the chat, a request is made to the database about the current state. The state is stored as an integer from 0 to 3. Next, the condition is checked, and depending on which digit the corresponding polling stage is performed.
It looks like this:

if int(condition) == 1:
        bot.register_next_step_handler(message, get_data2)

The problem is that this code only works the second time. Those. the function referenced by register_next_step_handler only works after the second chat message from the user, after the first one nothing happens. I read on the Internet, not only I encountered this problem, but I did not find a solution. I suspect that perhaps in this case some other logic of how the bots work is needed. Or maybe it's possible to do something so that the code would be processed the first time?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question