Answer the question
In order to leave comments, you need to log in
How can a chatbot wait for a user's response?
Using the VK API, the bot receives the user's last message and processes it. But what if the bot needs to wait for the user to send a message?
For example - a bot asks a person to enter a password or other response and should not respond until it receives this message. At the same time, what exactly will be in this message is unknown, so the usual if - else is indispensable. What can be done in such a situation?
Answer the question
In order to leave comments, you need to log in
Wait for a message from a specific ID. The ID can be obtained both from the message itself and in other ways, depending on the library used, for example:
def func(user_id):
for event in long_poll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.obj.from_id == user_id:
print('something')
The simplest option is to bind the field to a user, let's say "path". And conditionally create a structure like in a website. Those. all users initially have path = /
For example, he wrote "Menu" - You send it to path / menu - and you already process the following messages based on the place where the user is located.
In your case, something like:
A person wrote - you sent him to /password
Then, no matter what the person writes, you will process it along this path as entering a password. Well, then you also send the user to the desired path
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question