Skip to content

fix(gateway/telegram): use quoted fragment over full reply text - #23091

Closed
j2h4u wants to merge 2 commits into
NousResearch:mainfrom
j2h4u:fix/telegram-quote-text
Closed

fix(gateway/telegram): use quoted fragment over full reply text#23091
j2h4u wants to merge 2 commits into
NousResearch:mainfrom
j2h4u:fix/telegram-quote-text

Conversation

@j2h4u

@j2h4u j2h4u commented May 10, 2026

Copy link
Copy Markdown

What

When a user selects and cites a specific fragment of a message in Telegram (partial quote), the cited text is available in message.quote.text (a TextQuote object). The gateway was ignoring this and always using the full reply_to_message.text instead.

Why

Telegram's partial quote feature lets users highlight exactly the words they're replying to. Passing the full message text as reply context is misleading — the agent receives far more text than the user intended to reference.

Change

# Before
reply_to_text = message.reply_to_message.text or message.reply_to_message.caption or None

# After
if message.quote and message.quote.text:
    reply_to_text = message.quote.text
else:
    reply_to_text = message.reply_to_message.text or message.reply_to_message.caption or None

message.quote is None when the user replies without selecting a fragment (standard reply), so existing behaviour is fully preserved as a fallback.

How to test

  1. Send a long message to the bot
  2. In Telegram, select a short fragment of that message and reply to it (partial quote)
  3. Verify that reply_to_text in the resulting MessageEvent contains only the selected fragment, not the full message

Tested on: Linux (python-telegram-bot 22.6)

j2h4u added 2 commits May 10, 2026 14:01
When a user cites a specific fragment in Telegram (message.quote.text),
prefer that over the full replied message text/caption. The full text
is only used as fallback when no quote is present.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists labels May 10, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #22676 (already merged). This PR implements the same message.quote.text fix that landed in #22676. Also duplicates open #22709.

@j2h4u

j2h4u commented May 10, 2026

Copy link
Copy Markdown
Author

Closing — upstream fixed the same issue independently in the same release batch (#22619). The fix is now in main.

@j2h4u j2h4u closed this May 10, 2026
@j2h4u
j2h4u deleted the fix/telegram-quote-text branch August 14, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants