S
S
Sergey Bondarenko2019-05-29 18:17:21
Python
Sergey Bondarenko, 2019-05-29 18:17:21

Text responses when clicking on InlineKeyboardButton (pyTelegramBotAPI)?

Hello, how to implement text responses (send message) when clicking on InlineKeyboardButton?

@bot.message_handler(commands=['start'])
def any_msg(message):
    keyboard = types.InlineKeyboardMarkup()
    callback_button = types.InlineKeyboardButton(text="1", callback_data="1")
    keyboard.add(callback_button)
    bot.send_message(message.chat.id, "Я – сообщение из обычного режима", reply_markup=keyboard)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sound901, 2019-05-29
@saund901

@bot.callback_query_handler(func=lambda call: True)
def ans(call):
    kb = types.InlineKeyboardMarkup()
    cid = call.message.chat.id
    mid = call.message.message_id
    if call.data == "1":
        bot.edit_message_text('answer', cid, mid, reply_markup=kb, parse_mode='Markdown')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question