Skip to content

fix(telegram): honor bot ID mentions in text and photo captions - #140266

Merged
obviyus merged 3 commits into
openclaw:mainfrom
cai-ops:fix/telegram-hasbotmention-text-mention
Sep 9, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
cai-ops:fix/telegram-hasbotmention-text-mention

Conversation

@cai-ops

@cai-ops cai-ops commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Closes #140265

What Problem This Solves

Fixes mention-required Telegram groups ignoring messages that address the bot through a text_mention entity. 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.

Scenario Baseline efa6acb1aea2 Candidate 78da2dcb50b7
Bot-ID text mention Skipped; no turn or reply One turn and one reply
Bot-ID photo caption Skipped before download One image-bearing turn and one reply
Same label targeting another user No turn or reply No turn or reply
Plain display label No turn or reply No turn or reply
Username control One turn and reply One turn and reply
  • Real text/caption controls passed with emoji prefixes and correct UTF-16 offsets. Username mentions, replies to the bot, configured patterns, and addressed native commands retained their behavior; commands addressed to another bot were ignored.
  • Replies stayed in the actual non-general forum topic. Excluded-sender and disabled-group messages produced no turn or reply.
  • 115 focused tests passed. They include optional-argument compatibility, malformed helper input, group allowlist denial, and self-message filtering. The identity text/caption helper regressions fail on the baseline for the expected reason.
  • Exact-head CI is green: run 34049217537.
  • All 53 run-owned server messages and the created topic were removed. Persistent groups were preserved; the credential lease was released.

Scope: 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.

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S labels Sep 6, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 3:56 PM ET / 19:56 UTC (Revision 5).

ClawSweeper review

What this changes

Recognizes 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
Reviewed head: 78da2dcb50b77247d6d6fdbd06cabcc7cee7678b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-correct repair with useful regression coverage, successful exact-head CI, and relevant reported live before/after observations.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The updated body records real Telegram Test Server observations through the changed body and media gates at the reviewed head: bot-ID text and photo captions produce one turn and reply, while unrelated-user and plain-label controls remain silent. Username, topic, and denied-access observations address the prior requested controls; underlying raw traces were not independently replayed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The updated body records real Telegram Test Server observations through the changed body and media gates at the reviewed head: bot-ID text and photo captions produce one turn and reply, while unrelated-user and plain-label controls remain silent. Username, topic, and denied-access observations address the prior requested controls; underlying raw traces were not independently replayed.
Evidence reviewed 9 items Introduced change and caller coverage: The complete pinned merge-base-to-head diff adds an exact text_mention user-ID comparison and supplies the current bot ID from both production callers. Existing username and addressed-command detection remain intact.
Current main still needs the fix: The fetched main implementation recognizes username and command mentions but has no text_mention branch. A bot-ID entity whose visible label contains no username therefore remains unrecognized.
Latest release also lacks identity matching: The same detector in v2026.9.3 lacks text_mention recognition; this is not already-shipped work.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +6, Tests +175. Total +181 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 9 3 +6
Tests 2 175 0 +175
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 184 3 +181

Review metrics

None.

Technical review

Best 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.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The updated body records real Telegram Test Server observations through the changed body and media gates at the reviewed head: bot-ID text and photo captions produce one turn and reply, while unrelated-user and plain-label controls remain silent. Username, topic, and denied-access observations address the prior requested controls; underlying raw traces were not independently replayed.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated body records real Telegram Test Server observations through the changed body and media gates at the reviewed head: bot-ID text and photo captions produce one turn and reply, while unrelated-user and plain-label controls remain silent. Username, topic, and denied-access observations address the prior requested controls; underlying raw traces were not independently replayed.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Repairs a bounded Telegram addressing failure where identity mentions are silently skipped in mention-required groups.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated body records real Telegram Test Server observations through the changed body and media gates at the reviewed head: bot-ID text and photo captions produce one turn and reply, while unrelated-user and plain-label controls remain silent. Username, topic, and denied-access observations address the prior requested controls; underlying raw traces were not independently replayed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The updated body records real Telegram Test Server observations through the changed body and media gates at the reviewed head: bot-ID text and photo captions produce one turn and reply, while unrelated-user and plain-label controls remain silent. Username, topic, and denied-access observations address the prior requested controls; underlying raw traces were not independently replayed.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The change affects whether Telegram users receive replies to identity mentions; the updated Test Server observations demonstrate that visible behavior.

Evidence

What I checked:

  • Introduced change and caller coverage: The complete pinned merge-base-to-head diff adds an exact text_mention user-ID comparison and supplies the current bot ID from both production callers. Existing username and addressed-command detection remain intact. (extensions/telegram/src/bot/body-helpers.ts:350, 78da2dcb50b7)
  • Current main still needs the fix: The fetched main implementation recognizes username and command mentions but has no text_mention branch. A bot-ID entity whose visible label contains no username therefore remains unrecognized. (extensions/telegram/src/bot/body-helpers.ts:350, 2100687a64d5)
  • Latest release also lacks identity matching: The same detector in v2026.9.3 lacks text_mention recognition; this is not already-shipped work. (extensions/telegram/src/bot/body-helpers.ts:350, 1391f7cd2d40)
  • Updated real Telegram observations resolve prior feedback: The captured PR body, sourceRevision 60f38d6e45a6a33e6bb1e45b09ec2acdf9a2cbbe49b3233eac7fdbfa66790a48, reports real Test Server baseline/candidate observations: bot-ID text and photo captions change from skipped to one model turn and one reply, while unrelated-user and plain-label controls remain silent. It also records username, forum-topic, excluded-sender, and disabled-group controls. The REST body matched the supplied snapshot. These are reported live observations; this reviewer did not rerun the setup or inspect underlying raw traces. (78da2dcb50b7)
  • Authorization remains independent of addressing: Group and sender access checks reject denied updates separately from mention detection. The body caller rejects failed base access before resolving the body, and the media path retains command authorization before download. The patch does not turn a mention into sender authorization. (extensions/telegram/src/bot-message-context.ts:294, 78da2dcb50b7)
  • Public helper compatibility: The helper is exported through the Telegram API barrel. Its new argument is optional, the existing two-argument behavior remains unchanged, and focused coverage includes omitted identity, unrelated identity, malformed entity, caption, username, and body-gate cases. This preserves the existing API through a narrow repair without adding a competing helper or configuration. (extensions/telegram/api.ts:50, 78da2dcb50b7)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-06T16:22:22.388Z sha 0b21f5496c31364076efe945d6c40ac8e37fef6e :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T16:44:41.836Z sha 4a77b70 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T17:16:15.741Z sha 69a2371 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T17:44:30.361Z sha 78da2dc :: needs real behavior proof before merge. :: none

…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]>
@cai-ops
cai-ops force-pushed the fix/telegram-hasbotmention-text-mention branch from 0b21f54 to 4a77b70 Compare September 6, 2026 16:38
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 6, 2026
@cai-ops

cai-ops commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Update — precise root cause of the red checks (no code change needed):

checks-node-changed-extensions-bundle-6 failed during pnpm install, before any test ran (its Run Node test shard step was skipped). The failure is a third-party package's postinstall binary download returning HTTP 403:

@matrix-org/matrix-sdk-crypto-nodejs postinstall: Download Failed Error: Response status was 403
Error: ERR_PNPM_EXECUTOR_LIFECYCLE_SCRIPT_FAILED  →  pnpm install failed

This is a transient dependency-download/infra failure, unrelated to this change:

  • the diff touches no package.json or lockfile — only four extensions/telegram source/test files;
  • a clean pnpm install --frozen-lockfile of the identical lockfile succeeds locally, so the dependency graph is intact;
  • openclaw/ci-gate ("Verify selected CI lanes") is red only because it aggregates the required lanes and bundle-6 did not succeed.

All change-relevant lanes are green: check-lint, check-lint-core-1..5, check-prod-types, check-test-types (+ core shards), the extension package-boundary check, and every extension test bundle that installed successfully. Re-running the failed job should clear it; I don't have permission to trigger a re-run on this repository.

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]>
@cai-ops

cai-ops commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Added the requested real-behavior proof: extensions/telegram/src/bot-message-context.body.test.ts now drives the production caller resolveTelegramInboundBody and asserts that a group message tagging the bot via a text_mention (display-name tap — no @username, no mention entity) is dispatched (effectiveWasMentioned === true, not skipped), while a text_mention of a different user id is still skipped. Removing the text_mention branch makes the positive case fail, so the proof is non-vacuous. PR body updated.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

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]>
@cai-ops

cai-ops commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

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 bot-message-context.body.test.ts already drive a Telegram update through the production accessor resolveTelegramInboundBody, not just the helper. The update carries a text_mention entity and the assertions observe the actual skip-vs-dispatch decision that accessor produces — the message is not logged as skipping group message and effectiveWasMentioned === true (it proceeds to dispatch), while a text_mention for a different user id still returns null (skipped). Removing the text_mention branch flips the positive case, so the decision is driven by the change, not by the fixture. The media accessor resolveUnaddressedGroupMediaDisposition resolves mentions through the same getTelegramTextParts + hasBotMention(…, ctx.me?.id) path, and the caption + missing-user shapes are covered at that helper level.

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 requireMention group, tap the bot's display name (producing a text_mention, not an @username) and confirm it now replies — and/or point me at an existing integration harness that drives the inbound handler to an observed dispatch? I'm happy to add whatever reproducible test shape would satisfy the gate.

@obviyus obviyus self-assigned this Sep 9, 2026
@obviyus obviyus changed the title fix(telegram): treat text_mention of the bot as an explicit group mention fix(telegram): honor bot ID mentions in text and photo captions Sep 9, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 9, 2026
@obviyus
obviyus merged commit 9124f5a into openclaw:main Sep 9, 2026
126 checks passed
@obviyus

obviyus commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Bug: Mention-required groups skipped valid identity mentions of the bot.
  • Fix: The shared detector checks the bot ID supplied by both the body and media callers.
Before After
Bot-ID text mention skipped One turn and one reply
Bot-ID photo caption skipped before download One image-bearing turn and one reply
Other-user mention or plain display label ignored Still ignored

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.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 10, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: bot text_mention (display-name tap) in groups is not treated as a mention

2 participants