[Python] How to capture the updated (or new) message after clicking an inline button in...

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to automate a Telegram workflow using Telethon in Python. I interact with a third-party Telegram bot as a normal user account. The bot has inline buttons labeled “⬅”, “1/7”, “➡” to navigate different pages within a single message.

    Issue:

    After I click the inline button (either via GetBotCallbackAnswerRequest or await msg.click(...)), I want to retrieve the updated or new message text. However, Telethon doesn’t automatically return the updated text from the callback answer, but instead return always the same first message.

    `

    while True:
    try:
    # Wait for the next response. Use a short timeout (e.g. 3s)
    msg = await conv.get_response(timeout=3)
    #print(msg.stringify())
    # Append the message text (or the entire Message object if you want)
    all_bot_replies.append(msg.text)
    print(msg.text)
    """
    if msg.reply_markup is not None:
    for row in msg.reply_markup.rows:
    if len(row.buttons) > 2:
    button = row.buttons[2]
    #print(msg.stringify())

    # Click the button
    await msg.click(2)
    await msg.click(2)
    update_event = await conv.wait_event(events.MessageEdited)
    print("quaaaaaaaaaaa", update_event)
    """
    try:
    for row in msg.reply_markup.rows:
    button = []
    button.append(row.buttons)
    try:
    if button[0][2]:
    btn = button[0][2]
    page = button[0][1].text[0]
    finalpage = button[0][1].text[-1]
    callback_data = btn.data


    for i in range(int(page), int(finalpage)+1):
    print("stom qua")
    # con la callback clicco il bottone
    await client(GetBotCallbackAnswerRequest(
    peer=msg.chat.id,
    msg_id=msg.id,
    data=callback_data
    ))


    except IndexError:
    pass
    except AttributeError:
    pass
    except asyncio.TimeoutError:
    # No more messages arrived in 3 seconds -> done
    break

    # Store the list of replies for this email
    results = all_bot_replies`


    Im expecting to have the possibility to print the messages of the other pages.

    [url="https://stackoverflow.com/questions/79454189/how-to-capture-the-updated-or-new-message-after-clicking-an-inline-button-in-t"]Continue reading...[/url]

Compartilhe esta Página