Search code examples
pythontelegram-botpython-telegram-bot

python telegram bot api inlinekeyboardbutton not getting callback_data


python telegram bot api inlinekeyboardbutton not getting callback_data,

i'm using telebot libray,

this is how i created the buttons

            markup = types.ReplyKeyboardMarkup(row_width=2)
            b1 = types.InlineKeyboardButton("button 1", callback_data='1')
            b2 = types.InlineKeyboardButton('Button 2', callback_data='2')
            markup.add(b1, b2)
            bot.send_message(cid, 'message', reply_markup=markup)

the buttons appear and i can press them but nothing returns to my callback_query_handler

@bot.callback_query_handler(func=lambda call: True)
def callback_button(call):
    try:
        if call.message:
            cid = message.chat.id
            if call.data == '1':
                pass
            elif call.data == '2':
                pass
    except:
        pass

Solution

  • As it turned out, InlineKeyboardButton objects do not return callback as ReplyKeyboardButton objects.

    InlineKeyboardButton are sent as a message and they will appear within the message_handler