M
M
Michael2019-07-09 05:49:25
Python
Michael, 2019-07-09 05:49:25

How to set the sequence of handlers when creating a telegram bot [pyTelegramBotAPI]?

Good afternoon!
I can't figure out how to set the handler sequence.
How the bot works:
1) /start
2) select a category: games, books, music.
3) Write a title. (It doesn't matter what the person writes here, the answer is the same.)
4) thanks for contacting!
In the code itself, the first handler contains the category "Games" (if you start communicating with the bot with the word "Games", then there are no problems with the cycle), and if you write "Books" or "Music" to the bot, the bot immediately replies "Thank you for contacting ".
Please tell me how to implement this cycle correctly so that messages to the bot are not intercepted only by the first handler? (Added screenshot)
5d2400073445c910520570.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Shitskov, 2019-07-09
@Zarom

All except the 1st message - text. The text must be processed by one handler. Already in it you need to determine what text the user specified.
Concerning sequence - implement session storage for each user. You can start with a simple dictionary user_id => step_number. It just increases the counter of successful steps after the bot answers each one and check in your handler for the text to understand what the user's question is now and what to answer

M
Michael, 2019-07-09
@Mikhail_Ryt

Thanks for the answer.
But I can't put all the ifs in one handler. I would like to see this with an example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question