Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

telegram bots, how to request input from user?

I know how to use telegram commands, and know how to read what command has been executed. What I would like to do is something like this:

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

so far, i can read the /send_address command and reply with "hello,...." and obviously I can also read the answer of the user, just like I have read the /send_address command. Question is, how do i know if the answer he sends is in response to my "hello, please type your address.." request, or if he sent it just because? I could have 100 users chatting with the bot, would i have to store a variable for each user remembering that he sent the /send_address cmd?

like image 874
sharkyenergy Avatar asked Feb 21 '17 08:02

sharkyenergy


1 Answers

As I known, telegram has no way to save state for user. I use a table in database for saving comands of user.

How it works:

  1. User say /command
  2. Store /command for User.
  3. User say "something" we try to get data from database for this user. If we find out that previos message is command /command than do some action and save nowly added data (if you have multiple steps for some command)
like image 57
Danil Pyatnitsev Avatar answered Sep 23 '22 23:09

Danil Pyatnitsev