D
D
Dmitry Kolyada2019-03-08 18:08:00
In contact with
Dmitry Kolyada, 2019-03-08 18:08:00

How to save intermediate data when a person communicates with a bot?

Can you please tell me how can I store the intermediate data that the user reports to the bot?
You need to save data so that, roughly speaking, the user fills out the questionnaire through the bot.
I can come up with different options myself, for example, have a table in the database in which I will store the question id, user id, the time the question was sent and the time the answer was sent, and the answer itself. It seems not the worst option, but I think that with the proper load, the plate will reach unrealistic sizes, although of course it can be cleared of records older than N. There are probably other disadvantages of this solution.
Therefore, I'm interested in the best practice in this functionality. Clearly someone has already encountered this and solved this problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2019-03-08
@inoise

No one has come up with a better storage base. And then it all depends on the processes that you want to lay under this case. If something, storing several million records in the database is not a problem at all

D
Danil K., 2019-06-07
@Danya_Violet

@bot.message_handler(commands=['uiscreate'])
def uis_request_domain(message):
    if message.text.lower() == 'отмена':
        bot.send_message(message.from_user.id, 'Выполнение команды отменено')
        return
    send = bot.send_message(message.chat.id, 'Создание пользователя\nВведите почтовый домен:\n'
                                             'domain.ru')
    bot.register_next_step_handler(send, uis_request_data)


def uis_request_data(message):
    global domain_uis
    domain_uis = message.text.lower()
    if message.text.lower() == 'отмена':
        bot.send_message(message.from_user.id, 'Выполнение команды отменено')
        return
    send = bot.send_message(message.chat.id, 'Введите: ФИО должность телефон')
    bot.register_next_step_handler(send, create_uis)


def create_uis(message):
    first = message.text.split()[1]
    last = message.text.split()[0]
    middle = message.text.split()[2]
    phone = message.text.split()[4]
    position = message.text.split()[3]

<...>

and then you can both in the database and in the file and wherever you want

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question