How pyTelegramBotAPI handlers process incoming messages?

The essence of the following:

A simple bot to pyTelegramBotAPI. There is a SQLite database, in which each a group is stored the data you want to send to the user upon request.
Algorithm such: the user triggers the check himself in the group command /register, then sends a group number that is stored in shelve storage. Then the other team gets the right data for your group.

Here is an example handler for message /register:

def register(message):
 bot.send_message(, "Please state your group number (looks something like 2xxx).")
 group = message.text
 match = re.match('2[1-5][1-5][1-5]', group, flags=0)
 if len(match)>0 :
 bot.send_message( "Invalid group number, please register again.")
 else : 
 with as storage:
 storage[str(chat_id)] = group
 bot.send_message(, "Group updated successfully.")

How do the handlers of messages, i.e. inside the handler consistently "listen to messages"? For example, now there are after the command /register from the processing of the entire block. You need to create for each message a separate/attached handler? I can not understand how best to implement a dialogue with the client.
July 9th 19 at 13:11
3 answers
July 9th 19 at 13:13
Need to capture user state and depending on the current state to produce a particular operation. Then can build a dialogue
July 9th 19 at 13:15
How can I capture the status of the user?
July 9th 19 at 13:17
In my case used this magic:
msg = bot.send_message( config.start_auth_no_message)
bot.register_next_step_handler(msg, reg)

reg - the function that will handle the following message that user.

Find more questions by tags PythonTelegram