Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

not being able to sent a response to client inside a callback with query.answer() #4559

Closed as not planned
Labels
@henriquesati

Description

@henriquesati

Steps to Reproduce

  1. pip install python-telegram-bot --upgrade
  2. python main.py
  3. /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 tried
context.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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp