- Notifications
You must be signed in to change notification settings - Fork5.7k
Closed as not planned
Closed as not planned
Description
Steps to Reproduce
- pip install python-telegram-bot --upgrade
- python main.py
- /menu as command on the bot
Expected behaviour
send a new message to a user once a InlineKeyBoardButton is pressed
Actual behaviour
the button interface appears to be loading, but no response is sent
Operating System
Windows 10
Version of Python, python-telegram-bot & dependencies
Bot API 7.10
Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep 6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)]
Relevant log output
there is no error output, the client simply doesnt receive a response
Additional Context
I'm not being able to send a response to the client using query.answer('text') inside a callback function.
I also triedcontext.bot.answer_callback_query(callback_query_id=query.id, text="teste@@")
where query.id its retrieved from Update.callback_queryHere:
asyncdefbutton(update:Update,context:CallbackContext):query=update.callback_queryifquery.data=="option1":awaitquery.answer(text="ereeeer 1")elifquery.data=="option2":awaitquery.answer(text="ereeeer 2")else:awaitquery.answer(text="ereeeer not selected")query.answer(text="ereeeer@@1")
full code:
importloggingfromtelegramimportUpdate,InlineKeyboardButton,InlineKeyboardMarkup,Botfromtelegram.extimport (ApplicationBuilder,CommandHandler,CallbackContext,CallbackQueryHandler,ContextTypes,)logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',level=logging.INFO)logger=logging.getLogger(__name__)asyncdefstart(update:Update,context:ContextTypes.DEFAULT_TYPE):awaitcontext.bot.send_message(chat_id=update.effective_chat.id,text="I'm a bot, please talk to me!")asyncdefchain_to_send_menu(update:Update,context:CallbackContext):keyboard= [ [InlineKeyboardButton("Option 1",callback_data="option1")], [InlineKeyboardButton("Option 2",callback_data="option2")], ]reply_markup=InlineKeyboardMarkup(keyboard)awaitupdate.message.reply_text("Welcome! Please choose an option:",reply_markup=reply_markup )asyncdefbutton(update:Update,context:CallbackContext):query=update.callback_queryifquery.data=="option1":awaitquery.answer(text="ereeeer 1")elifquery.data=="option2":awaitquery.answer(text="ereeeer 2")else:awaitquery.answer(text="ereeeer not selected")awaitcontext.message.reply_text("Welcome!2323e an option:" )query.answer(text="ereeeer@@1")defmain():application= (ApplicationBuilder() .token(TOKEN) .read_timeout(10) .write_timeout(10) .concurrent_updates(True) .build() )CommandHandler('start',start)start_handler=CommandHandler('start',start)menu_handler=CommandHandler('menu',chain_to_send_menu)x=CallbackQueryHandler(button)application.add_handler(menu_handler)application.add_handler(start_handler)application.add_handler(x)application.run_polling()if__name__=="__main__":main()