S
S
Syndr0me2019-07-09 09:59:28
Node.js
Syndr0me, 2019-07-09 09:59:28

How to properly organize the reception and reading of messages when developing a telegram bot?

Hello. There is a telegram bot written in nodejs , telegraf , which has a list of tasks.
The user enters the bot and receives a random task, how can I make it so that the user's input is correctly processed and attributed to his task?
5d243b3b5c6d3778728931.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2019-07-09
@Syndr0me

I store the current state of the user in the database to determine at what stage and depth of the menu the user is.
In your example:
a user with id 12345 takes a task - we write the id in the database table and, for example, take quest as the second field
. Further, in the subsequent actions, before processing the message from the user, check in the database what state the user is in and, based on this, take certain actions. For example, after the user has taken the task, a response is expected from him. with any message, it is checked that the user has a take quest, so his message is the answer, we check the answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question