Skip to content

Add configurable reply-to message behavior for Telegram bot - #10115

Closed
g2nnyS wants to merge 9 commits into
AstrBotDevs:masterfrom
g2nnyS:master
Closed

g2nnyS wants to merge 9 commits into
AstrBotDevs:masterfrom
g2nnyS:master

Conversation

@g2nnyS

@g2nnyS g2nnyS commented Sep 17, 2026

Copy link
Copy Markdown

This pull request introduces a new configuration option to control whether the Telegram bot replies by quoting (replying to) the original message that triggered its response. The change is implemented end-to-end: from configuration, through platform logic, to the user interface and internationalization. The default behavior is not to quote messages, but users can now choose to enable quoting in private chats, group chats, or both.

Key changes include:

Telegram Bot Reply-to Behavior

  • Added a new configuration option telegram_reply_to_message (with values: off, private, group, all) to control the reply quoting behavior for Telegram bot responses. This includes updates to the default config, config schema, and i18n files for English, Chinese, and Russian. [1] [2] [3] [4] [5]
  • Updated the Telegram adapter (tg_adapter.py) and event (tg_event.py) logic to respect this configuration: when enabled, the bot will quote the triggering message in the appropriate chat context; when disabled, any reply components are stripped from outgoing messages to ensure no quoting occurs. [1] [2] [3] [4] [5] [6]

User Display Improvements

  • Improved the construction of the sender's display name in Telegram messages, now showing both display name and username when available, for better clarity in logs and UI.

These changes provide more flexible and user-friendly control over how the Telegram bot interacts in conversations, matching user preferences and platform expectations.

Modifications / 改动点

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

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


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • [] 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 📚 I checked the affected WebUI instructions and screenshots in docs/zh and docs/en against the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog.
    / 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新 docs/zhdocs/en 的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Allow users to control whether Telegram bot responses quote the triggering message while improving sender identification.

New Features:

  • Add configurable Telegram reply-to behavior for private chats, group chats, both, or neither.
  • Expose the Telegram reply-to setting in the default configuration and localized dashboard configuration metadata.

Enhancements:

  • Improve Telegram sender names by combining display names with usernames when available.

g2nnyS and others added 8 commits June 26, 2026 23:26
Introduces a new `telegram_reply_to_message` configuration option, allowing
users to control whether the bot automatically quotes the original message
when sending a reply. This behavior can be set for `private` chats, `group`
chats, `all` chats, or turned `off`.

This provides greater flexibility in how the bot interacts in different Telegram
chat environments.

Additionally, this commit improves the resolution of sender nicknames for
Telegram messages, prioritizing a combination of first/last name and username
for a more comprehensive display.
This improves the user experience and internationalization of the recently
introduced 'telegram_reply_to_message' configuration by providing clear,
localized labels for its options in the dashboard.
When the `telegram_reply_to_message` configuration is set to prevent replies, remove any `Reply` components that may have been added to the message chain by other global settings. This ensures the Telegram platform's specific setting to disable quoting is always respected, overriding any default reply behavior.

@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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/platform/sources/telegram/tg_adapter.py" line_range="764" />
<code_context>
             platform_meta=self.meta(),
             session_id=message.session_id,
             client=self.client,
+            reply_to_message=self.reply_to_message,
         )

</code_context>
<issue_to_address>
**issue (broader_impact):** The reply-to configuration is propagated to `TelegramPlatformEvent`, but `send_streaming` never uses it when constructing the Telegram payload. Streaming responses therefore do not quote the triggering message even when `telegram_reply_to_message` is set to `private`, `group`, or `all`.

**Triggers:** When Telegram streaming responses are enabled and reply quoting is configured.

**Suggested fix:** Apply the same `should_reply` logic to the streaming payload and include the triggering message ID for the supported Telegram send operations.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the setting or scope logic is wrong, Telegram responses can be sent with an incorrect reply association or have an explicit Reply component suppressed, and those messages remain visible after a revert. The configuration can be changed back and future responses recover, but already-sent messages cannot be fully restored by rerunning the bot.

Blocking findings: astrbot/core/platform/sources/telegram/tg_adapter.py:764


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread astrbot/core/platform/sources/telegram/tg_adapter.py
@g2nnyS

g2nnyS commented Sep 17, 2026

Copy link
Copy Markdown
Author

@copilot

1 similar comment
@g2nnyS

g2nnyS commented Sep 17, 2026

Copy link
Copy Markdown
Author

@copilot

@g2nnyS

g2nnyS commented Sep 17, 2026

Copy link
Copy Markdown
Author

no comment

@g2nnyS g2nnyS left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I need more context to generate a professional GitHub issue response. Please provide the specific issue content, the background of the discussion, or the exact question that needs to be addressed.

@g2nnyS g2nnyS left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Could you please provide the specific details or the content of the GitHub issue for which you need a professional reply drafted? This will help me create an accurate and contextually appropriate response.

@g2nnyS g2nnyS closed this Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant