S
S
s1veme2020-08-29 07:29:34
Python
s1veme, 2020-08-29 07:29:34

Telebot - How to implement receiving messages with callback_data?

Made inline buttons in the telegram bot:

@bot.callback_query_handler(func = lambda call: True)
def print_all_commands(call): 
    if call.data == 'print_all_commands':
        markup = types.InlineKeyboardMarkup()
        btn_command = types.InlineKeyboardButton("❗Как тебя зовут?", callback_data="commands")
        markup.add(btn_command)
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Выберите действие:", reply_markup=markup)


But bot.callback_query_handle can't process any sent text, how to realize that when the button is clicked - What's your name? , the bot waited for one line of text, and then did some action. But without pressing the button - he did not expect anything. When you click on another button - just waiting for the text.
(There will be many different buttons that should then accept some text)

I tried to do this, but it does not work:
elif call.data == "kick":
        @bot.message_handler(content_types = ["text"])
        def kick_text(message):
            bot.send_message(message.chat.id, "Введите, то, что вам надо:")


I’ll explain why I don’t want to use the keyboard - a regular keyboard displays something in the chat, that is, it will clog it well, and through callback - you can simply change the message and buttons.

How to implement this?

If I didn't explain well, let me know.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2020-08-29
@aleksegolubev

Learn how to use register_next_step_handler
Example
Essentially this is an implementation of waiting for input from the user.
Through callback_query_handler you catch the button click, and then you process this click with 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