H
H
howuu2019-06-09 11:00:51
Bots
howuu, 2019-06-09 11:00:51

How to implement input in telebot?

Right now I have a function that accepts all messages and then

@bot.message_handler(func=lambda m: True)
def messages(message):
  if 'hello' in message.text:
    hello(message)
  else:
    something(message)

I want to make a function that takes the user's mood, through message.text,
the user presses the button and the function starts its work, then what the user enters needs to be caught and saved to the database, the problem is that if you intercept messages with the option above, then they can other commands will be executed, and you need to come up with a format, since you will need to perform similar actions for your favorite color and favorite song. While I have an idea to send a message: Enter mood in the format
Mood: your mood", and catch the keyword, but I feel that this is an uncomfortable bike, maybe there are other options, for example, block @bot.message_handler(func=lambda m: True) for a while performing the mood check function?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2019-06-09
@Allepta

Just add a CallbackQueryHandler and do some processing in it.

H
howuu, 2019-06-09
@howuu

In general, I came up with this solution: I store the user's state in the database, when it comes to the introduction of color, I check the state, thereby blocking all other functions, it's easier to show
the get_current_state() function requests the user's state when he wants to specify something, his state from regular changes to for example color_except ( condition != regular, purely for example), this decorator weighs higher than others, therefore it is executed first, which blocks other functions, I will be glad if someone has to

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question