O
O
orbly2020-04-28 10:06:27
Python
orbly, 2020-04-28 10:06:27

How to make the bot wait for a response at a certain moment?

How can I implement waiting for a response from the user at a certain moment in a telegram bot? For example, like BotFather in the attached image.
5ea7d5cc23a12701243059.png
The bottom line is this: the user clicks on a certain button, he is prompted to enter the name of the task, he sends a message and the bot writes this message to the database. How to write to the database, I understand, I can not only understand how to get the user's message.

@bot.callback_query_handler(func=lambda call: True)
def callback_logic(call):
    if call.data == 'toDoList':
        todo = todolist.show_list(u_id=call.message.chat.id)
        text = '\n'.join([f'{todo_task}' for todo_task, in todo])
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
                              text='Список твоих дел: \n\n' + text, reply_markup=toDoKeyboard)
    elif call.data == 'events':
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
                              text='Список мероприятий: ', reply_markup=eventsKeyboard)
    elif call.data == 'schedule':
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
                              text='Расписание: ', reply_markup=scheduleKeyboard)
    elif call.data == 'back':
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
                              text='Главное меню', reply_markup=menu)
    elif call.data == 'addTask':
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
                              text='Введите название задачи', reply_markup=toDoSubKeyboard)


What should be added after the bot asks for a task name? I tried call.message.text, but in this case it reads the message of the bot, not the user.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2020-04-28
@orbly

google register_next_step_handler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question