Node Telegram bot api, make chain conversation between user

You can do it in different ways.

  1. You can store the "state" the user is in yourself
  2. You can use multiple commands that will work on their own, but you just give the user the feeling of being guided
  3. You can use the ForceReply of the Bot API

Alright. So for 1. I'd say you have some benefits. You can actually guide the user and restrict access to some commands, when he is not in the proper state. So let's say he wants to buy Popcorn but he's in the shoestore you'd disallow the command by checking the saved user state.

For 2. you would always allow the user to use /buy and /buy_popcorn and /buy_shoe. But depending on your answers you just give him a specific amount of possible selections.

User: /buy

What do you want to buy? /shoes or /food :Bot

User: /food

How about some Popcorn? Use /buy_popcorn :Bot

User: /buy_shoe

Alright. Shoes added to cart :Bot

This would be allowed, but the user would have to manually write /buy_shoe

The 3. possible way is using the ForceReply. The user will automatically get an answer to message. So when he uses /buy_shoe he will answer to the last message the bot sent. You will also get the message the user answered to in the message from the api. You can check if the message the user answered to is the proper precondition / proper message for the command and then restrict or allow the command.

User: /buy

What do you want to buy? /shoes or /food :Bot

User: [Answer to: What do you...] /food

How about some Popcorn? Use /buy_popcorn :Bot

User: [Answer to: How about some...] /buy_shoe

Sorry, but you're currently in the Food Store :Bot

It comes down to personal preference, I guess. But all of it has pros and cons and you have to decide if you want to allow specific commands without a precondition.

This List may not be complete. It could be that there are other ways, I didn't think about. But these 3 are ways I know of.