fix(gateway): prefer Telegram native partial quote text in reply context - #22633
Closed
KhanCold wants to merge 1 commit into
Closed
fix(gateway): prefer Telegram native partial quote text in reply context#22633KhanCold wants to merge 1 commit into
KhanCold wants to merge 1 commit into
Conversation
When a Telegram user replies using the native quote feature to select only part of a previous message, the adapter was ignoring the selected quote and injecting the entire replied-to message as reply_to_text. Now checks message.quote (TextQuote) first and uses quote.text when available, falling back to the full reply_to_message text only when no native quote exists. Fixes NousResearch#22619
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Description
When a Telegram user replies using the native quote feature to select only part of a previous message, the adapter was ignoring the selected quote and injecting the entire replied-to message as
reply_to_text. This can materially change the user's intent — the model sees the full previous message instead of just the quoted portion.Root Cause
The reply-context extraction in
_build_message_event()only checkedmessage.reply_to_message.text/.caption, which represents the full replied-to message. Telegram'spython-telegram-botlibrary exposesMessage.quote/TextQuotefor the selected quoted portion, but the adapter never checked it.Fix
Prefer native quote text when available:
message.quoteexists and has text, usequote.textasreply_to_textmessage.reply_to_message.message_idasreply_to_message_idTesting
This should be covered by a regression test that builds a Telegram
Messagewith bothreply_to_message.textandquote.text, then verifies the resultingMessageEvent.reply_to_textuses the quote text, not the full replied-to message.Related
Fixes #22619
Related to reply-context behavior added in #1594