Repository navigation
feat(telegram): expose update id and message date to interactive plugin handlers - #133267
MokSeinNacken wants to merge 5 commits into
Conversation
…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.
|
🦞👀 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 real behavior proof before merge. What this changesExpose Telegram update IDs and callback-message dates to interactive plugin handlers, with SDK documentation and dispatch tests. Review scores
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 Decision needed
Before merge
Findings
Agent review detailsHow this fits togetherTelegram’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]
Technical reviewBest 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:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against efcb55c85364. Merge-risk optionsMaintainer options:
SecurityNone. EvidenceWhat I checked:
PR surfaceSource +23, Tests +213, Docs +11. Total +247 across 7 files. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
Reviewed October 7, 2026, 5:09 AM ET / 09:09 UTC (Revision 6). |
- 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.
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.
|
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 Targeted verification (this head): the loopback integration proof ( 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 ( |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
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_idor the callback message'sdateinside the dispatched handler context. Both values already exist atthe 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_idfor itsown bookkeeping (
resolveTelegramUpdateIdinextensions/telegram/src/telegram-ingress-spool.ts), and the callbackmessage carries its mandatory
datefield. This change forwards bothvalues verbatim into
TelegramInteractiveHandlerContextas new requiredfields
updateIdandmessageDate. The change is purely additive: nosynthesis, no fallback, no transformation, and no change to callback
routing,
handledsemantics, agent fallback, authentication, or approvallogic.
User Impact
Plugin authors of interactive Telegram handlers can now:
update via
updateId. The field isnumber | nulland isnullonlywhen no valid
update_idis available (synthetic updates or malformedvalues); consumers must treat
nullfail-closed (no synthesis, nosubstitute value);
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 existingresolveTelegramUpdateId(ctx.update)helper (source:
ctx.update.update_id), typednumber | nullto matchthe helper's actual return type under the repository's
stricttsconfig;
messageDate— taken directly fromcallbackMessage.date(source:
callback_query.message.date), typednumber.Both values pass through the existing callback router into
handleTelegramInteractiveCallback, which forwards them into thedispatched plugin context unchanged.
Runtime changes
extensions/telegram/src/bot-handlers.callback-router.ts: importresolveTelegramUpdateId; passupdateId: resolveTelegramUpdateId(ctx.update)and
messageDate: callbackMessage.dateinto the existinghandleTelegramInteractiveCallbackcall. No other routing logicchanges.
extensions/telegram/src/bot-handlers.callback-router-controls.ts:accept
updateId/messageDatein the call parameters and forward theminto the
ctxobject ofdispatchTelegramPluginInteractiveHandler.No dispatch,
handled, fallback, or authentication logic changes.Type changes
extensions/telegram/src/interactive-dispatch.ts:TelegramInteractiveHandlerContextgains two required fields:updateId: number | null—nullfor synthetic updates or anyupdate lacking a valid
update_id(missing, non-numeric, negative,or unsafe-integer values); valid Bot API
callback_queryupdatesalways provide a number. Consumers must treat
nullfail-closed.messageDate: number— Unix seconds from the authoritativecallbackQuery.message.date.src/plugins/interactive-contract.test-helpers.ts: test-helper typemirrors the same two fields.
Security / trust-boundary rationale
exposed: both values are public Telegram update metadata already
present on the ingress path.
outbound calls. Tests remain offline.
value is ever synthesized, hashed, derived, or replaced, and a missing
or invalid
update_idyields an explicitnull(fail-closed) ratherthan a fabricated identifier. This preserves the trust boundary between
the Telegram ingress and plugin handlers.
handledsemantics, agentfallback, command handling, or authentication rules.
Backward compatibility
that the Telegram extension itself constructs; existing handler
registrations compile and run unchanged (they simply do not read the
new fields).
dispatchTelegramInteractive,handledsemantics, namespace matching,auth, and agent fallback are untouched.
(
src/plugins/interactive-contract.test-helpers.ts) andsrc/plugins/interactive.test.ts(fixed fixture values andvalue-equality assertions).
Tests
src/plugins/interactive.test.ts: fixture now includesupdateId: 424242andmessageDate: 1710000000, with value-equalityassertions that the dispatched
TelegramInteractiveHandlerContextreceives both values verbatim.
different routing,
handled, fallback, or dedup behavior.git apply --checkagainst currentmainis clean; therepository's standard lanes (
pnpm build && pnpm check && pnpm test,and
pnpm test:extension telegramfor the extension surface) run in CI.Scope exclusions
spool/dedup logic.
fallback.
no CHANGELOG edit (maintainers add changelog entries on landing).
Evidence
Evidence
Real behavior proof (loopback): A real grammY Bot with an HTTP Bot API
loopback (127.0.0.1) drives a Telegram
callback_queryupdate through the realcallback router and generic interactive dispatcher into a temporary registered
handler. The handler receives the authoritative ingress values verbatim:
updateId === 424242,messageDate === 1710000000(seeinteractive-ingress-proof.loopback.integration.test.ts). No live Telegramaccount, no second poller, no webhook, no owner-approval state change.
src/plugins/interactive.test.tsdispatches aTelegram callback with fixed fixture values (
updateId: 424242,messageDate: 1710000000) and asserts the handler receives both valuesverbatim in
TelegramInteractiveHandlerContext.updateIdis typednumber | null,matching the existing
resolveTelegramUpdateIdhelper's return typeunder the repository's
stricttsconfig;messageDate: numbermatchesgrammY's mandatory
Message.date. The change contains no synthesized orfallback values.
(
git apply --check) to currentmain; the PR diff is exactly 5 files,+29/−0, purely additive.
PR). The extension test lane (
pnpm test:extension telegram) and theinteractive plugin unit tests cover the touched surface.