fix(telegram): exclude forum topic system messages from implicitMention#32262
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a4eb2120a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/telegram/bot-message-context.ts
Outdated
| const implicitMention = botId != null && replyFromId === botId; | ||
| const replyToBotMessage = botId != null && replyFromId === botId; | ||
| const isReplyToSystemMessage = | ||
| replyToBotMessage && msg.reply_to_message?.from?.is_bot === true && !msg.reply_to_message?.text; |
There was a problem hiding this comment.
Treat captioned/media bot replies as implicit mentions
The new system-message filter classifies any reply with falsy reply_to_message.text as a Telegram forum system message, but normal bot media messages also commonly have no text (they use caption or media payloads instead). In groups/topics with requireMention enabled, replies to those legitimate bot media messages now lose implicit mention detection and are skipped, which regresses the previous replyFromId === botId behavior for ongoing conversations.
Useful? React with 👍 / 👎.
Greptile SummaryFixed
Confidence Score: 4/5
Last reviewed commit: 7a4eb21 |
src/telegram/bot-message-context.ts
Outdated
| const isReplyToSystemMessage = | ||
| replyToBotMessage && msg.reply_to_message?.from?.is_bot === true && !msg.reply_to_message?.text; |
There was a problem hiding this comment.
media messages (photo/video) sent by the bot also have no text field (they use caption instead), so they'd be incorrectly treated as system messages and wouldn't trigger implicitMention
consider also checking that there's no caption or media fields to distinguish true system messages from media messages:
| const isReplyToSystemMessage = | |
| replyToBotMessage && msg.reply_to_message?.from?.is_bot === true && !msg.reply_to_message?.text; | |
| const isReplyToSystemMessage = | |
| replyToBotMessage && msg.reply_to_message?.from?.is_bot === true && !msg.reply_to_message?.text && !msg.reply_to_message?.caption; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/bot-message-context.ts
Line: 469-470
Comment:
media messages (photo/video) sent by the bot also have no `text` field (they use `caption` instead), so they'd be incorrectly treated as system messages and wouldn't trigger `implicitMention`
consider also checking that there's no `caption` or media fields to distinguish true system messages from media messages:
```suggestion
const isReplyToSystemMessage =
replyToBotMessage && msg.reply_to_message?.from?.is_bot === true && !msg.reply_to_message?.text && !msg.reply_to_message?.caption;
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7be828992
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/telegram/bot-message-context.ts
Outdated
| !msg.reply_to_message?.text && | ||
| !msg.reply_to_message?.caption; |
There was a problem hiding this comment.
Preserve implicit mentions for captionless bot media replies
The new isReplyToSystemMessage guard treats any bot reply target with no text and no caption as a forum system message, but normal bot messages like stickers, voice notes, and photos sent without captions also satisfy that condition. In requireMention groups, replying to those legitimate bot messages now stops counting as an implicit mention, so users’ reply-chain follow-ups are skipped even though this worked before the commit. This should key off actual Telegram forum-system markers (for example service-message fields) rather than missing text/caption alone.
Useful? React with 👍 / 👎.
When a Telegram Forum topic is created by the bot, Telegram generates a system message with from.id=botId and empty text. Every subsequent user message in that topic has reply_to_message pointing to this system message, causing the implicitMention check to fire and bypassing requireMention for every single message. Add a guard that recognises system messages (is_bot=true with no text) and excludes them from implicit mention detection, so that only genuine replies to bot messages trigger the bypass. Closes openclaw#32256 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address Greptile review feedback: bot media messages (photo/video) use caption instead of text, so they would be incorrectly classified as system messages. Add !caption guard to the system message check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Stickers, voice notes, and captionless photos from the bot also lack text and caption fields, so the previous check incorrectly classified them as system messages and suppressed implicitMention. Switch to checking for Telegram's forum_topic_* / general_forum_topic_* service-message fields which only appear on actual service messages. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7c061e7 to
95aaf9e
Compare
|
Landed via temp rebase onto main.
Thanks @scoootscooob! |
Summary
implicitMentionincorrectly firing for every message in Telegram Forum topics created by the botfrom.id=botId, empty text) when a Forum topic is created, and all subsequent messages in that topic havereply_to_messagepointing to itbot-message-context.tsthat detects system messages (is_bot=truewith no text) and excludes them from implicit mention detectionimplicitMentionas beforeTest plan
bot.test.ts)Closes #32256
🤖 Generated with Claude Code