Skip to content

feat: honor partial Telegram reply quotes#9236

Open
Last-emo-boy wants to merge 1 commit into
AstrBotDevs:masterfrom
Last-emo-boy:feat/7938-telegram-partial-quote
Open

feat: honor partial Telegram reply quotes#9236
Last-emo-boy wants to merge 1 commit into
AstrBotDevs:masterfrom
Last-emo-boy:feat/7938-telegram-partial-quote

Conversation

@Last-emo-boy

@Last-emo-boy Last-emo-boy commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #7938

Modifications / 改动点

  • Use Telegram TextQuote.text as the exact quoted reply content.

  • Keep the full replied message as the fallback when no non-empty partial quote exists.

  • Add regression coverage with emoji and a non-zero UTF-16 quote position.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

  • uv run pytest -q tests/test_telegram_adapter.py: 12 passed
  • ruff format --check .: passed
  • ruff check .: passed

Checklist / 检查清单

  • The feature was discussed with a maintainer in the linked issue.
  • My changes have been well-tested, and verification results are provided above.
  • No new dependencies are introduced.
  • My changes do not introduce malicious code.

Summary by Sourcery

Honor Telegram partial reply quotes when constructing reply components while preserving existing behavior as a fallback.

New Features:

  • Support using Telegram reply quote text as the replied message content when present.

Enhancements:

  • Fallback to the full replied message when no non-empty quote text is available in Telegram replies.

Tests:

  • Add Telegram adapter tests covering partial quote handling, empty or missing quote text, and emoji with non-zero UTF-16 quote positions.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for partial quotes in Telegram replies by extracting the quoted text from update.message.quote when available, and updates the mock helpers and tests accordingly. The feedback suggests using getattr to safely access the quote attribute to avoid potential AttributeError exceptions on older library versions, and handling whitespace-only quotes by checking quote_text.strip() along with adding a corresponding test case.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread astrbot/core/platform/sources/telegram/tg_adapter.py
Comment thread tests/test_telegram_adapter.py
@Last-emo-boy Last-emo-boy force-pushed the feat/7938-telegram-partial-quote branch from f08022f to 6cea126 Compare July 14, 2026 02:43
@Last-emo-boy Last-emo-boy marked this pull request as ready for review July 14, 2026 02:48
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. labels Jul 14, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

reply_abm = await self.convert_message(reply_update, context, False)

if reply_abm:
quote_text = update.message.quote.text if update.message.quote else None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, does update.message.quote exists in the previous version of telegram SDK AstrBot using?

I have not double check yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked.
It does appear cuz Message.quote appeared since v20.8
whereas Astrbot requirements were python-telegram-bot>=22.0 and bumped to >=22.6 in PR #5726
so the attribute exists in both the previous and current supported versions. When a message has no partial quote, its value is simply None, so direct access should be safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Telegram 适配器:支持「部分引用」(TextQuote),让模型只看到用户实际选中的片段

2 participants