A
A
astorme2018-05-14 22:24:34
MongoDB
astorme, 2018-05-14 22:24:34

How to make a Telegram bot state machine to receive answers to several questions in turn?

Please tell me how to make a state machine to receive responses from users (you need to take the first name, last name and age as an example), as I understand it, you need to use a database and wiretapping templates, how can this be connected for better work?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2018-05-15
@astorme

Recently I made a Telegram bot on Google Spreadsheet and Google Apps Script. You can store key-value data there .
When a message arrives, the id of the user who wrote it is known. Based on this id, a prefix for the keys is made, for example, "TG_12345" where 12345 is the user's id.
Possible dialogs are described in the type dictionary

{ "новый пользователь": [ // название диалога
  {"propmt": "Введите ваше имя"}, // первый вопрос
  {"propmt": "Введите email"},  // второй
  {"propmt": "ник в телеграме"}, // третий
], 
  "ещё какой-то диалог":[/* вопросы */]
}

And you need to store the state of the dialog for the current user: name, step number and previously completed answers. The total keys can be:
TG_12345_DIALOG: "новый пользователь" // из словаря диалогов
TG_12345_STEP: 2 // текущий шаг, ожидаемый ответ
TG_12345_REPLY_0: "Иван Петров" // полученные ответы
TG_12345_REPLY_1: "[email protected]"

A
Alexey, 2018-05-15
@MAKAPOH

I recommend looking at books or articles on the subject of "automatic programming".

A
Alexander Taratin, 2018-05-15
@Taraflex

https://github.com/telegraf/telegraf/blob/develop/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question