Skip to content

feat(telegram): expose update id and message date to interactive plugin handlers - #133267

Closed
MokSeinNacken wants to merge 5 commits into
openclaw:mainfrom
MokSeinNacken:feat/telegram-interactive-context-update-metadata
Closed

MokSeinNacken wants to merge 5 commits into
openclaw:mainfrom
MokSeinNacken:feat/telegram-interactive-context-update-metadata

Conversation

@MokSeinNacken

@MokSeinNacken MokSeinNacken commented Aug 30, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Plugin authors building interactive Telegram handlers (namespace-scoped
callback flows such as confirmation or approval prompts) currently cannot
access the authoritative Telegram update_id or the callback message's
date inside the dispatched handler context. Both values already exist at
the ingress — the incoming update and the parsed callback message carry
them — but they are dropped before the plugin context object is built.
Handlers that need to correlate an interaction with its originating
Telegram update, or reason about the message timestamp, have no reliable
source and are forced to synthesize timestamps or correlation keys, which
is fragile and weakens auditability of Telegram-driven plugin flows.

Why This Change Was Made

The Telegram ingress already resolves the authoritative update_id for its
own bookkeeping (resolveTelegramUpdateId in
extensions/telegram/src/telegram-ingress-spool.ts), and the callback
message carries its mandatory date field. This change forwards both
values verbatim into TelegramInteractiveHandlerContext as new required
fields updateId and messageDate. The change is purely additive: no
synthesis, no fallback, no transformation, and no change to callback
routing, handled semantics, agent fallback, authentication, or approval
logic.

User Impact

Plugin authors of interactive Telegram handlers can now:

  • correlate a callback interaction with the exact originating Telegram
    update via updateId. The field is number | null and is null only
    when no valid update_id is available (synthetic updates or malformed
    values); consumers must treat null fail-closed (no synthesis, no
    substitute value);
  • read the callback message's Unix timestamp via messageDate
    (always a number, matching grammY's mandatory Message.date).

Existing handlers are unaffected: the fields are additive, and no existing
dispatch behavior changes.

Proposed change

Forward the two authoritative values already present at the Telegram
ingress into TelegramInteractiveHandlerContext:

  • updateId — resolved via the existing resolveTelegramUpdateId(ctx.update)
    helper (source: ctx.update.update_id), typed number | null to match
    the helper's actual return type under the repository's strict
    tsconfig;
  • messageDate — taken directly from callbackMessage.date
    (source: callback_query.message.date), typed number.

Both values pass through the existing callback router into
handleTelegramInteractiveCallback, which forwards them into the
dispatched plugin context unchanged.

Runtime changes

  • extensions/telegram/src/bot-handlers.callback-router.ts: import
    resolveTelegramUpdateId; pass updateId: resolveTelegramUpdateId(ctx.update)
    and messageDate: callbackMessage.date into the existing
    handleTelegramInteractiveCallback call. No other routing logic
    changes.
  • extensions/telegram/src/bot-handlers.callback-router-controls.ts:
    accept updateId/messageDate in the call parameters and forward them
    into the ctx object of dispatchTelegramPluginInteractiveHandler.
    No dispatch, handled, fallback, or authentication logic changes.

Type changes

  • extensions/telegram/src/interactive-dispatch.ts:
    TelegramInteractiveHandlerContext gains two required fields:
    • updateId: number | null — null for synthetic updates or any
      update lacking a valid update_id (missing, non-numeric, negative,
      or unsafe-integer values); valid Bot API callback_query updates
      always provide a number. Consumers must treat null fail-closed.
    • messageDate: number — Unix seconds from the authoritative
      callbackQuery.message.date.
  • src/plugins/interactive-contract.test-helpers.ts: test-helper type
    mirrors the same two fields.
  • No other public type is touched.

Security / trust-boundary rationale

  • No new secrets, credentials, identities, or sensitive fields are
    exposed: both values are public Telegram update metadata already
    present on the ingress path.
  • No new network surface: no poller, no webhook, no new consumer, no
    outbound calls. Tests remain offline.
  • Values are passed through verbatim from the authoritative source; no
    value is ever synthesized, hashed, derived, or replaced, and a missing
    or invalid update_id yields an explicit null (fail-closed) rather
    than a fabricated identifier. This preserves the trust boundary between
    the Telegram ingress and plugin handlers.
  • No change to callback namespace matching, handled semantics, agent
    fallback, command handling, or authentication rules.

Backward compatibility

  • Additive only: new required fields are introduced on the context type
    that the Telegram extension itself constructs; existing handler
    registrations compile and run unchanged (they simply do not read the
    new fields).
  • dispatchTelegramInteractive, handled semantics, namespace matching,
    auth, and agent fallback are untouched.
  • OpenClaw's own tests are extended only in the shared test helper
    (src/plugins/interactive-contract.test-helpers.ts) and
    src/plugins/interactive.test.ts (fixed fixture values and
    value-equality assertions).

Tests

  • src/plugins/interactive.test.ts: fixture now includes
    updateId: 424242 and messageDate: 1710000000, with value-equality
    assertions that the dispatched TelegramInteractiveHandlerContext
    receives both values verbatim.
  • Existing interactive-handler tests continue to pass; no test asserts
    different routing, handled, fallback, or dedup behavior.
  • Validation: git apply --check against current main is clean; the
    repository's standard lanes (pnpm build && pnpm check && pnpm test,
    and pnpm test:extension telegram for the extension surface) run in CI.

Scope exclusions

  • No changes to the Telegram ingress, polling, webhook handling, or
    spool/dedup logic.
  • No changes to plugin SDK semantics, namespace matching, or agent
    fallback.
  • No new dependencies, no new configuration, no database/schema changes,
    no CHANGELOG edit (maintainers add changelog entries on landing).
  • No refactoring beyond the minimal additive pass-through.

Evidence

Evidence

Real behavior proof (loopback): A real grammY Bot with an HTTP Bot API
loopback (127.0.0.1) drives a Telegram callback_query update through the real
callback router and generic interactive dispatcher into a temporary registered
handler. The handler receives the authoritative ingress values verbatim:
updateId === 424242, messageDate === 1710000000 (see
interactive-ingress-proof.loopback.integration.test.ts). No live Telegram
account, no second poller, no webhook, no owner-approval state change.

  • Focused test coverage: src/plugins/interactive.test.ts dispatches a
    Telegram callback with fixed fixture values (updateId: 424242,
    messageDate: 1710000000) and asserts the handler receives both values
    verbatim in TelegramInteractiveHandlerContext.
  • Type/runtime consistency: updateId is typed number | null,
    matching the existing resolveTelegramUpdateId helper's return type
    under the repository's strict tsconfig; messageDate: number matches
    grammY's mandatory Message.date. The change contains no synthesized or
    fallback values.
  • Clean apply against main: the patch applies cleanly
    (git apply --check) to current main; the PR diff is exactly 5 files,
    +29/−0, purely additive.
  • CI: repository checks run against this PR (status visible on the
    PR). The extension test lane (pnpm test:extension telegram) and the
    interactive plugin unit tests cover the touched surface.

…dlerContext

Forward the authoritative Telegram update_id and callback message date
into the plugin interactive handler context so consumers can implement
persistent update dedup and time-window checks without synthesizing
values. Additive only; no changes to handled/fallback semantics,
namespace matching, auth, or agent behavior.
@clawsweeper

clawsweeper Bot commented Aug 30, 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: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 30, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Expose Telegram update IDs and callback-message dates to interactive plugin handlers, with SDK documentation and dispatch tests.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, useful implementation with supplemental boundary coverage, limited by the unresolved live-proof gate and incomplete field documentation.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Merge readiness

⛔ Blocked before merge - 6 items remain

This PR retains a useful, distinct API enhancement absent from current main and the latest release. The pass-through implementation is sound, but the previous documentation finding and real-Telegram proof gap remain unresolved.

Priority: P3
Reviewed head: 9337b17a9134f6e075f13737850f85d6da6d4d4f
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should Telegram interactive handlers publicly expose updateId and messageDate with nullable-ID and zero-date semantics?
  • Recommendation: Adopt the metadata fields: Expose both ingress values through the existing context and document their unavailable-value semantics.
  • Why: The implementation is bounded, but source correctness cannot establish acceptance of a new permanent plugin API contract, and no recorded maintainer decision covers it.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: the reported grammY loopback pass exercises the production callback router and dispatcher with synthetic updates and stubbed authorization. It is useful supplemental coverage, but the scoped Telegram guide requires a real callback showing ingress update_id and message date reaching the handler. Redacted terminal output or logs suffice; screenshots or recordings are welcome when useful. Remove credentials and private identifiers. Updating the PR body should trigger review automatically; otherwise ask a maintainer for @clawsweeper re-review. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Document the zero date for inaccessible callback messages (P3) - Telegram's pinned types permit CallbackQuery.message to be inaccessible, with date: 0. The router forwards that value unchanged, so describing messageDate only as a Unix timestamp can make handlers interpret an unknown date as an actual epoch timestamp. Document the zero sentinel here and in the context field comment, and tell consumers to treat it as unavailable.
  • Resolve merge risk - Two required fields expand the exported Telegram plugin context contract without recorded maintainer acceptance of their permanent semantics.
  • Resolve merge risk - The current head has verified merge conflicts; the refreshed callback path has not been reviewed or validated.
  • Complete next step - Resolve the verified merge conflicts and validate the refreshed callback path.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P3] Document the zero date for inaccessible callback messages — docs/plugins/sdk-overview.md:421-422
Agent review details

How this fits together

Telegram’s callback router receives button interactions and passes their context to registered plugin handlers through the shared interactive dispatcher. These fields let handlers read metadata from the originating update and message.

flowchart TD
  A[Telegram callback update] --> B[Telegram callback router]
  B --> C[Resolve update metadata]
  C --> D[Interactive callback context]
  D --> E[Shared namespace dispatcher]
  E --> F[Registered plugin handler]
Loading

Technical review

Best possible solution:

Keep one Telegram-owned metadata pass-through, preserve existing handler behavior, and explicitly define nullable update IDs and the inaccessible-message zero-date sentinel.

Do we have a high-confidence way to reproduce the issue?

Not applicable to the feature request; current main and release source confirm the fields are absent. The documentation defect is directly established by the pinned Telegram types, without executing target code.

Is this the best way to solve the issue?

Yes for the implementation boundary: forwarding ingress values through the existing Telegram context is narrower than adding another dispatcher. The proposed contract still needs the zero-date qualification and maintainer acceptance.

Full review comments:

  • [P3] Document the zero date for inaccessible callback messages — docs/plugins/sdk-overview.md:421-422
    Telegram's pinned types permit CallbackQuery.message to be inaccessible, with date: 0. The router forwards that value unchanged, so describing messageDate only as a Unix timestamp can make handlers interpret an unknown date as an actual epoch timestamp. Document the zero sentinel here and in the context field comment, and tell consumers to treat it as unavailable.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against efcb55c85364.

Merge-risk options

Maintainer options:

  1. Confirm the additive contract (recommended)
    Accept the two context fields with documented null and zero semantics, then resolve conflicts while preserving existing handlers.
  2. Decline the API expansion
    Close the proposal if these metadata fields should remain outside the supported plugin contract.

Security

None.

Evidence

What I checked:

PR surface

Source +23, Tests +213, Docs +11. Total +247 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 23 0 +23
Tests 3 213 0 +213
Docs 1 11 0 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 247 0 +247

Review metrics

Metric Value Why it matters
Production versus test growth Production +23; tests and test support +213; docs +11 Production growth implements the two-field capability through the existing owner boundary; most added code is supplemental loopback coverage.
Public context contract 2 required fields added; 0 config options added The new metadata semantics become a plugin-facing promise requiring an explicit API direction.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is a bounded plugin-author ergonomics enhancement, with no established broken default user workflow.
  • merge-risk: 🚨 compatibility: The exported Telegram handler context gains two required fields whose permanent unavailable-value semantics lack recorded maintainer acceptance.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide redacted real-Telegram callback output showing both ingress values reaching the registered handler.
  • Document messageDate=0 as unavailable and record acceptance of the public context semantics.
  • Resolve the verified conflicts and validate the refreshed Telegram callback path.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-30T11:07:15.868Z sha 6f16e3e :: needs real behavior proof before merge. :: [P2] Document the new public handler context fields
  • reviewed 2026-08-30T16:51:53.158Z sha 95c6f1d :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-31T12:17:00.238Z sha 9337b17 :: needs real behavior proof before merge. :: none
  • reviewed September 22, 2026, 9:46 AM ET / 13:46 UTC (Revision 4) sha unknown :: needs real behavior proof before merge. :: [P3] Document the zero date for inaccessible callback messages
  • reviewed September 22, 2026, 9:46 AM ET / 13:46 UTC (Revision 5) sha unknown :: needs real behavior proof before merge. :: [P3] Document the zero date for inaccessible callback messages

Reviewed October 7, 2026, 5:09 AM ET / 09:09 UTC (Revision 6).

Argent Dev Team added 2 commits August 30, 2026 17:40
- Fix import ordering for resolveTelegramUpdateId in the callback router
  (oxfmt check-lint compliance).
- Document updateId (source: update_id via resolveTelegramUpdateId, null for
  missing/invalid values, never synthesized) and messageDate (source:
  callback_query.message.date, Unix seconds) in the plugin SDK overview.
Loopback integration proof: a real grammY Bot with an HTTP Bot API loopback
(127.0.0.1) drives a Telegram callback_query update through the real callback
router and generic interactive dispatcher into a temporary registered handler.
The handler receives the authoritative ingress values verbatim (updateId and
messageDate from update_id / callback_query.message.date). No live Telegram
account, no second poller, no webhook, no owner-approval state change.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M and removed size: XS labels Aug 30, 2026
@clawsweeper clawsweeper Bot added the proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. label Aug 30, 2026
The loopback proof test imported core plugin internals via relative paths
(../../src/plugins/*) which do not resolve inside the extension test
shard (ERR_MODULE_NOT_FOUND) and failed strict typecheck (TS2307/TS2532).

Switch to the public plugin-sdk subpath exports
(openclaw/plugin-sdk/plugin-runtime, plugin-test-runtime), accept
ctx: unknown in the temporary handler with an internal type narrow, and
access received[0] via optional chaining. Runtime behavior unchanged.
@MokSeinNacken

Copy link
Copy Markdown
Author

Maintainer note — CI state, check-lint root cause and proof status (tested head: 9337b17)

check-lint failure root cause (not a code issue): the aggregate check-lint job was canceled by a runner shutdown signal, not by a lint violation. Job log: ##[error]The runner has received a shutdown signal... and ##[error]The operation was canceled at 12:41 UTC while [oxlint:extensions] was still running (the step reported finished 1s after the shutdown signal). All check-lint-core-* shards and every other check on this head (QA Smoke CI 1-6, Critical Quality, Security High group, Opengrep, CI-gate prerequisites) passed. Contributors cannot re-run the canceled job without admin rights on the repository; a fresh run should be green.

Targeted verification (this head): the loopback integration proof (extensions/telegram/src/interactive-ingress-proof.loopback.integration.test.ts) passes locally on 9337b17 — a real grammY bot with a localhost Bot API loopback drives a real callback_query update through the real callback router and generic interactive dispatcher; the registered handler receives updateId and messageDate verbatim from update.update_id / callback_query.message.date. No synthesis, no substitution.

Real-Telegram Test Server evidence: not yet available from this contributor environment — no dedicated test-environment bot credentials exist here, and production credentials are intentionally not usable for tests. Happy to add redacted Test Server evidence once a test-environment bot token can be provisioned.

The change remains purely additive (+247/−0): authoritative Telegram interactive callback ingress metadata (updateId, messageDate) for downstream consumers, with null fail-closed for synthetic/missing updates. Requesting re-review when convenient.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. labels Sep 22, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@vincentkoc

Copy link
Copy Markdown
Member

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

@vincentkoc vincentkoc closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants