Skip to content

fix(telegram): exclude forum topic system messages from implicitMention#32262

Merged
steipete merged 4 commits intoopenclaw:mainfrom
scoootscooob:fix/telegram-forum-implicit-mention-system-msg
Mar 2, 2026
Merged

fix(telegram): exclude forum topic system messages from implicitMention#32262
steipete merged 4 commits intoopenclaw:mainfrom
scoootscooob:fix/telegram-forum-implicit-mention-system-msg

Conversation

@scoootscooob
Copy link
Contributor

Summary

  • Fixes implicitMention incorrectly firing for every message in Telegram Forum topics created by the bot
  • The root cause is that Telegram auto-generates a system message (from.id=botId, empty text) when a Forum topic is created, and all subsequent messages in that topic have reply_to_message pointing to it
  • Adds a guard in bot-message-context.ts that detects system messages (is_bot=true with no text) and excludes them from implicit mention detection
  • Genuine replies to bot messages (with non-empty text) still trigger implicitMention as before

Test plan

  • 5 new unit tests covering:
    • System message (empty text, is_bot=true) → implicitMention NOT triggered
    • Empty-string text system message → implicitMention NOT triggered
    • Real bot reply (non-empty text) → implicitMention triggered as expected
    • Whitespace-only text → implicitMention triggered (not a system message)
    • Reply from different user → implicitMention NOT triggered
  • All 18 bot-message-context tests pass
  • All existing implicit mention regression tests pass (bot.test.ts)
  • 631/635 telegram tests pass (4 pre-existing failures in custom commands unrelated to this change)

Closes #32256

🤖 Generated with Claude Code

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

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;

Choose a reason for hiding this comment

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

P1 Badge 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-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

Fixed implicitMention incorrectly firing for every message in Telegram Forum topics by detecting and excluding system messages (bot messages with empty text) from implicit mention detection.

  • Added guard that checks for is_bot=true with no text to identify system messages
  • Comprehensive test coverage with 5 new unit tests covering system messages, empty strings, real bot replies, whitespace-only text, and different user replies
  • All 18 bot-message-context tests pass, existing implicit mention regression tests pass
  • One minor edge case: media messages (photos/videos with captions but no text) may be incorrectly treated as system messages

Confidence Score: 4/5

  • Safe to merge - fixes a real bug with solid test coverage
  • The fix correctly addresses the forum topic system message issue with comprehensive tests. Score reflects a minor edge case with media messages that could be refined, but doesn't block the core improvement
  • Pay attention to src/telegram/bot-message-context.ts:469-470 - consider the media message edge case

Last reviewed commit: 7a4eb21

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +469 to +470
const isReplyToSystemMessage =
replyToBotMessage && msg.reply_to_message?.from?.is_bot === true && !msg.reply_to_message?.text;
Copy link
Contributor

Choose a reason for hiding this comment

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

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:

Suggested change
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.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +472 to +473
!msg.reply_to_message?.text &&
!msg.reply_to_message?.caption;

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

scoootscooob and others added 4 commits March 2, 2026 23:31
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>
@steipete steipete force-pushed the fix/telegram-forum-implicit-mention-system-msg branch from 7c061e7 to 95aaf9e Compare March 2, 2026 23:32
@steipete steipete merged commit 28c88e9 into openclaw:main Mar 2, 2026
8 checks passed
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm -s vitest run src/telegram/bot-message-context.implicit-mention.test.ts && pnpm -s tsgo
  • Land commit: 95aaf9e
  • Merge commit: 28c88e9

Thanks @scoootscooob!

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

Labels

channel: telegram Channel integration: telegram size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Telegram Forum: implicitMention incorrectly triggered by topic system messages

2 participants