I am developing a telegram bot in the Python programming language using the telebot library (pyTelegramBotApi). At the moment when I’m making buttons, I decided to use InlineKeyboardMarkup. The following questions arise, how to get the name of this button by clicking on the button. I need to get the index of an item in the list by the name I need to get from the button name.
@bot.callback_query_handler(func=lambda call: True)
def callback_query(call):
if call.data == 'SUBCATEGORIES_BTN':
sub_id = names.index(???) # Here I have to insert the name from the button name
2
Answers
@bot.message_handler(content_types=['text'])
def text(message):
There is no such thing as a button ‘name’.
The only value that is returned by Telgram is the
data
attribute (calledcallback_data
) that you’ve provided on the button. The text the user sees on the button is not given.The
data
is available ascall.data
as you’re already using in your code.For a complete exaxmple on how to use the InlineKeyboard, consider taking a look at the
pyTelegramBotApi Inline Keyboard Example