Telegram bots, how to request input from the user?

I know how to use telegram commands and I know how to read which command was executed. I would like to do the following:

User: /send_address
Bot: Hello, please type your address..
User: my address...

so far I can read the command / send _address and answer "hello, ....", and obviously I can also read the user's response, just like I read the command / send _address. The question is, how do I know if he answers my query "hello, please enter your address .." or if he sent it just because? I could have 100 users chatting with the bot, do I need to store a variable for each user, remembering that he sent / send _address cmd?

+4
source share
1 answer

As I know, a telegram has no way to save state for the user. I use a table in a database to store user codes.

How it works:

  • User say / command
  • Save / command for user.
  • The user says "something", we are trying to get data from the database for this user. If we find out that the previous message is a command / command, than some action and save now the added data (if you have several steps for a certain command)
+7
source

Source: https://habr.com/ru/post/1670383/


All Articles