Repository navigation
fix(telegram): honor bot ID mentions in text and photo captions - #140266
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 3:56 PM ET / 19:56 UTC (Revision 5). ClawSweeper reviewWhat this changesRecognizes mentions targeting the Telegram bot’s user ID in messages and photo captions, with regression coverage for unrelated users and existing username mentions. Merge readiness✅ Ready for maintainer review This remains a useful fix: current main and the latest release still miss identity mentions. The updated Telegram Test Server observations resolve the previous proof request, and no blocking patch defects were found. Priority: P2 Review scores
Verification
How this fits togetherThe Telegram plugin checks incoming messages and captions against group addressing policy before downloading media or starting an agent turn. The shared mention detector supplies addressing facts while separate checks enforce sender and group authorization. flowchart TD
A[Telegram message or caption] --> B[Sender and group authorization]
B --> C[Shared mention detector]
D[Current bot identity] --> C
C --> E{Mention policy satisfied?}
E -->|Yes| F[Media processing and agent turn]
E -->|No| G[Intentional skip or ambient ingest]
F --> H[Policy-controlled reply]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +6, Tests +175. Total +181 across 5 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep one shared identity-aware mention detector for text and captions while preserving sender authorization, existing addressing forms, and two-argument API behavior. Do we have a high-confidence way to reproduce the issue? Yes. Current main’s detector returns false for a bot-targeted text_mention without a username or matching configured pattern, causing mention-required text and caption gates to skip it; this review established that path from source. Is this the best way to solve the issue? Yes. Extending the existing detector and passing bot identity through both callers fixes the missing addressing form without duplicating policy or changing stored settings. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2100687a64d5. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
…tion A group message that tags the bot by tapping its display name produces a text_mention entity (entity text is the display name, not @username), which hasBotMention did not recognize. Under requireMention such a message was skipped with no reply, even though Telegram delivered it as addressing the bot. Add a text_mention branch to hasBotMention keyed on the bot's own id (already available at both call sites as ctx.me?.id). Additive and back-compatible: callers that pass no id keep the previous behaviour, and a text_mention of any other user is ignored. Reply-to-bot is unchanged (handled via implicitMentionKinds). Tests: new body-helpers.text-mention.test.ts covers resolves-to-bot, other-user, and no-id (back-compat). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
0b21f54 to
4a77b70
Compare
|
Update — precise root cause of the red checks (no code change needed):
This is a transient dependency-download/infra failure, unrelated to this change:
All change-relevant lanes are green: |
Adds two tests through the production caller resolveTelegramInboundBody: a group message tagging the bot via a text_mention (display-name tap, no @username, no mention entity) is dispatched with effectiveWasMentioned=true, and a text_mention targeting a different user id is still skipped. This proves the fix at the caller boundary, not only on hasBotMention in isolation, and the positive case fails if the text_mention branch is removed (non-vacuous). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Added the requested real-behavior proof: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…sername regression Use ent.user?.id so a malformed text_mention without a user object is ignored rather than throwing. Add regression cases: an @username mention still matches when a bot id is passed, a text_mention targeting the bot in a caption matches (getTelegramTextParts falls back to caption entities), and a text_mention with no user does not match (and does not throw). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks for the re-review and the clear rubric — glad the patch reads as source-correct (no code findings). On the real-behavior gate: the caller-level tests in What these tests don't include is the final leg — an actual Telegram delivery producing an observed reply — which needs a live bot in a real group. I don't have a non-production test bot/group to demonstrate that reproducibly here. Could a maintainer run a quick live check — in a |
|
Thanks @cai-ops! Proof: Real Telegram Test Server messages carrying bot-ID mentions now produce one turn and one reply in text and photo captions. Independent acceptance checked incoming updates, user-side events, model requests, and outgoing receipts.
Username, emoji-offset, reply, pattern, native-command, forum-topic, and authorization controls passed. All 115 focused tests passed, and exact-head CI is green. All 53 test-owned server messages and the test topic were removed; the credential lease was released. This proves protocol-level identity mentions. It does not claim every Telegram client's display-name-tap gesture, real albums, or alternate outbound reply modes. Missing-group denial and self-message filtering have focused test coverage. |
…claw#140266) Recognize Telegram text_mention entities that target the current bot ID in both message bodies and media captions. Preserve username mentions, optional helper calls, and existing sender, group, reply, command, and topic policy. Real Telegram Test Server proof reproduced skipped identity text and photo-caption mentions on the baseline and one turn/reply for each on the candidate. Other-user and plain-label controls stayed silent. Independent acceptance, 115 focused tests, formatting/lint, and exact-head CI passed. Closes openclaw#140265. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #140265
What Problem This Solves
Fixes mention-required Telegram groups ignoring messages that address the bot through a
text_mentionentity. The same failure affects photo captions: the bot receives the message but does not reply.Why This Change Was Made
The shared mention detector now compares the entity's user ID with the current bot ID. Both the message body and media prefilter supply that identity. The optional argument preserves existing two-argument helper calls.
User Impact
Bot-targeted identity mentions activate the bot in text and photo captions. Mentions of another user and plain display labels remain subject to the existing mention policy.
Evidence
Real Telegram Test Server proof used one leased bot/user pair, mention-required groups, and a deterministic local model endpoint. Raw incoming updates, user-side events, model requests, and outgoing receipts were checked by an independent validator.
efa6acb1aea278da2dcb50b7Scope: this proves real protocol-level identity mentions. It does not claim every Telegram client's display-name-tap gesture. Missing-group allowlist denial is covered by focused handler tests; the live group-denial case used a disabled group. Incoming-bot filtering and combined-message offsets use source/focused proof, and no real album or alternate outbound reply mode was claimed.