- Notifications
You must be signed in to change notification settings - Fork5.7k
Closed
Description
I'm not being able to send a response to the client usingquery.answer('text')
inside a callback function.
I also tried
context.bot.answer_callback_query(callback_query_id=query.id,text="teste@@")
where query.id its retrieved fromUpdate.callback_query
intended behavior: send a new message to a user once aInlineKeyBoardButton
is pressed
current behavior: the button interface appears to be loading, but no response is sent
python -V: 3.12.6
python-telegram-bot -V = 21.6
client: telegram desktop
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)# set higher logging level for httpx to avoid all GET and POST requests being loggedlogging.getLogger("httpx").setLevel(logging.WARNING)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 )awaitupdate.message.reply_text("Welcome!2323e 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")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()
Metadata
Metadata
Assignees
Labels
No labels