Creating A Handler By Clicking On Dynamic Inline Buttons
I have dynamically created buttons in an array keyboard = InlineKeyboardMarkup() keyboard.row_width = 2 for i in range(0, len(adress)): keyboard.add(InlineKeyboardButton(adress
Solution 1:
When a users clicks on an InlineKeyboardButton
with callback_data
, that results in an CallbackQuery
. A CallbackQuery
does not contain info about the text of the button that was clicked, but only about the callback_data
the button had. So if you want to know the text associated with that button I recommend to make the callback_data
unique per button. You could
- put that text directly into the
callback_data
- make the
callback_data
some unique identifier and store a mapping identifier → text - make the
callback_data
some unique identifier and extract the text by checking which of the buttons incallback_query.message.reply_markup.keyboard
has thatcallback_data
. Note that this doesn't work for callback queries from inline messages, is those don't bring along thecallback_query.message
Personally I'd recommand the second solution.
Post a Comment for "Creating A Handler By Clicking On Dynamic Inline Buttons"