el valuta
el valuta

Reputation: 317

Telegram bot wait for users reply and validate it

I have a question regarding communication logic of a telegram bot with users. The main point is to realize how to make telegram bot understand that he has to wait for some user's reply.

For example - I have a settings menu which is connected with some user settings in database.

So user click on "Settings" button in the menu and gets the list of options with the InlineKeyboardMarkup:

Option1 Option2 Option3

How is better to organise logic to make bot understand that after user has tapped some option, bot has to wait for user's reply, validate it, and so on, and if user tapped at that moment another option, to swich to it, or force user to cancel previous one.

I am working on php and using https://telegram-bot-sdk.readme.io

Thank you for your answers!

Upvotes: 1

Views: 3659

Answers (1)

ariaby
ariaby

Reputation: 902

You need to keep some kind of state in your database or cache for that specific user. Whenever you receive an update, you need to check if the user is in a specific state, for example filling a form or changing settings and what stage they are in. Then you route the update data to the relevant part of your code. Make sure to reset your state when you receive main commands like /start or /cancel, you don't want to trap the user in a state if something goes wrong.

Upvotes: 4

Related Questions