N
N
NooBick2020-08-28 22:32:06
Python
NooBick, 2020-08-28 22:32:06

How to make each person have their own dialogue?

For example: the first person answers the question, he already has a question 5/10. Then, if the second person writes to him, then he will also have a 5/10 question. And the second person can answer for the first. How to implement it in telegram? So that everyone has their own dialogue with the bot, and not the same.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-08-28
@SoreMix

Create a dictionary and write down which person has which question?
https://pythonworld.ru/tipy-dannyx-v-python/slovar...

S
shurshur, 2020-08-29
@shurshur

Well, look, just on the fingers is the simplest type of interaction. Suppose there is a dialogue state:
undefined or 0 - the user did not write anything, but pressed / start - we answer with the button and transfer to state 1.
1 - the user pressed the button - we ask for the phone and transfer to state 2.
2 - the user entered the phone - we do what we need and return to state 0.
So we start a dictionary:
user_states = dict()
Next, for each message, we do:

try:
  user_states[message.from_user.id]
except KeyError:
  user_states[message.from_user.id] = 0

if user_states[message.from_user.id] == 0:
  bot.send_message (посылаем кнопку)
  user_states[message.from_user.id] = 1
elif user_states[message.from_user.id] == 1:
  bot.send_message (спрашиваем телефон)
  user_states[message.from_user.id] = 2
elif user_states[message.from_user.id] == 2:
  bot.send_message (как прикажете, господин)
  do_somethine_awesome
  user_states[message.from_user.id] = 0

If it’s not clear how to turn this into working code, then it’s obviously too early for you to write bots, learn the language first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question