Hey folks! I’m working on a Telegram bot using Python and I’m stuck with handling inline keyboard button presses. My code works fine until the user hits an inline keyboard button. Here’s a snippet of what I’ve got:
def handle_update(update):
if 'callback_query' in update:
query = update['callback_query']
data = query['data']
if data == '1':
# Handle button press
send_message(query['message']['chat']['id'], 'You pressed the button!')
elif 'message' in update:
# Handle regular messages
process_message(update['message'])
# Main bot loop
while True:
updates = get_updates()
for update in updates:
handle_update(update)
I’m trying to make it respond when the user presses the ‘Next’ button (with callback_data ‘1’). Right now, nothing happens when it’s clicked. I know I should be tracking the callback query somehow, but I’m not sure how to do it properly with my current setup.
Any ideas on what I’m doing wrong or how to fix this? Thanks in advance for your help!