Working with python telegram bot v20+, how can I trigger distinct functions from individual InlineKeyboardButtons? For example, the ‘First’ button should initiate a support function.
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import Application, ContextTypes
async def initiate(update: Update, context: ContextTypes.DEFAULT_TYPE):
buttons = [
[InlineKeyboardButton('First', callback_data='first'), InlineKeyboardButton('Second', callback_data='second')],
[InlineKeyboardButton('Third', callback_data='third')]
]
keyboard = InlineKeyboardMarkup(buttons)
await update.message.reply_text('Welcome!')
await update.message.reply_text('Please choose an option:', reply_markup=keyboard)
async def handle_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
callback = update.callback_query
await callback.answer()
await callback.edit_message_text(text=f'You selected: {callback.data}')
if callback.data == 'first':
await callback.message.reply_text('Support function has been triggered!')