Skip to content

feat(telegram): show widgets as interactive Telegram message widgets - #196991

Merged
obviyus merged 26 commits into
mainfrom
openclaw/telegram-message-widgets
Nov 11, 2026
Merged

obviyus merged 26 commits into
mainfrom
openclaw/telegram-message-widgets

Conversation

@obviyus

@obviyus obviyus commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Agents in a Telegram private chat could not show show_widget dashboards, charts, checklists or polls. They fell back to text tables or images.

User Impact

User impact: with the new opt-in setting channels.telegram.widgets: true, show_widget in a private chat with the bot sends a Telegram message widget (Bot API 10.4). Tapping it updates that same widget in place. Typed messages still start new messages, so the chat keeps its order.

Default: off. Older Telegram clients cannot render widgets, the same compatibility problem that made richMessages opt-in in #93279. With the setting off, nothing changes: show_widget behaves as before, and taps on earlier widgets are dropped. /status shows Telegram widgets: on/off. Groups, channels and DM topics are always unchanged.

Why This Change Was Made

  • Core (show_widget):
    • A current-channel presenter now gets the agent's own widget code, a stable widget name and an optional state.
    • A presenter can replace the browser-host authoring rules with its own and declare a bounded state field.
    • A call with state and no widget_code updates the tapped widget. An explicitly empty state clears it.
    • Presenter message results can carry advisory notes; the tool result passes them to the model while reporting the widget as delivered.
    • When a presenter replaces the authoring rules, its widget code can't be pinned to the browser dashboard, because that code targets the channel's own runtime. pin=true with such code returns a clear error. Pinned reports still work.
    • The tool result now tells the model not to restate a widget in text.
  • Config: new channels.telegram.widgets and channels.telegram.accounts.<id>.widgets booleans (default off), with a config UI hint, docs and a /status line. The channel config-surface budget goes from 4003 to 4005 for these two paths, because a compatibility opt-in needs a setting, like richMessages.
  • Telegram plugin:
    • sendWidget with size checks; widgets in private chats only (never in topics, since taps come back without a thread), always sent with allow_queries.
    • widget_query taps are acknowledged as soon as they are durably admitted, then routed as agent turns.
      • Only allowlisted senders, checked against the live config on every tap.
      • No / or ! commands.
      • At most 10 per minute per widget; repeated request text is dropped for a minute. A durable replay of the same query id is not counted again.
      • If routing fails before dispatch, or dispatch reports a retryable failure, the tap is recorded as failed-retryable so durable ingress retries it instead of dropping it.
    • Each tap message includes the widget's stored state and code, so it works after /new or compaction.
    • In a tap turn, unchanged code edits the widget's data in place with editMessageWidgetData. New code always becomes a new message.
    • Widget and tap records live in two new namespaces of the existing plugin-state store. Nothing existing is rewritten and no schema changes, so upgrading leaves current data as it is. Once Telegram accepts a widget, a failed record write is logged, and the send still counts as delivered.
  • Trial run before sending:
    • Each widget runs once in quickjs-wasi 3.6.3, the same pinned engine Code Mode uses. It runs on the shared compute pool with a 1 s and 64 MB limit.
    • The run uses a stand-in DOM with the real TelegramWidget API (theme colors and viewer included), runs 3 s of timers and taps every enabled button. State updates replay the stored code with the old state, then the new one.
    • It follows Telegram's contracts: an empty or missing state reads as null, and request() resolves with { result }.
    • Exact problems go back to the model to fix, and the widget is not sent:
      • script errors and endless loops
      • removed elements, unsupported CSS (vh, sticky, scrolling, color-mix()) and network use
      • more than 2,000 elements or 400 CSS rules, and request() outside a tap
    • Approximate findings never block. The widget is sent, and the model gets them as notes on the show_widget result:
      • more than 16 translucent or shadowed elements (Telegram's paint limit), from a CSS projection that can't match Telegram's renderer exactly
      • undefined/NaN shown on screen
    • Widgets that use web APIs the trial run doesn't model (URL, crypto, ...) are sent unchecked. TextEncoder and TextDecoder are supplied.
    • If the checker itself fails, the widget is sent unchecked.
    • The checker was written from the public widget docs. No Telegram client code is used; their runtime is GPL-2.0.

Evidence

  • Live Telegram Test Server (leased bot plus TDLib 1.8.70 user, real models through the Claude CLI, 20 prompts modelled on widget requests seen in production):

    Model Prompts that got a widget Widgets that passed Telegram's validator
    Sonnet 5.5 15/20 15/15
    Opus 5.5 16/20 16/16
    Haiku 5.5 9/20 9/9
  • Taps on real widgets updated them in place with no extra message: poll vote, hotel pick, and a checklist's "Done for the day" sent from a later session.

  • Authorization through final effects (Test Server, head code, Sonnet 5.5, 2026-11-11). The allowlist was edited live in the Gateway config file, and each edit was hot-reloaded ([reload] config source revision N accepted). Model turns are counted from cli turn log lines; widget state and bot messages are read from the tester's chat.

    Case Model turns Widget state New bot messages
    Allowed sender taps Voice (control) +2 {"w":0,"v":0,"p":0} → {"w":0,"v":1,"p":0}, in place 0
    Tester removed from allowFrom, then taps Widgets 0 unchanged 0 (the tap is acknowledged, then dropped)
    Allowed sender taps Projects, tester removed 3 s later +3 p → 1, in place 0
    Baseline: ordinary text message, tester removed 3 s later +2 n/a 1 ("pong")

    A denied sender never reaches a model or Telegram. Revocation after a turn has been admitted does not cancel that turn. This matches how ordinary text messages already behave, so widget taps add no new path.

  • Upgrade from the latest stable release (pnpm test:docker:published-upgrade-survivor, baseline [email protected], candidate packed from 843ccf6): passed in 946 s.

    • The lane installs 2026.11.3, applies its config recipe, and seeds the state database and plugin data. It then updates to the candidate and asserts automatic migration and survival of config and state. It runs doctor, then starts the Gateway and checks its status probes.
    • All 49 phases passed, including assert-automatic-migration, assert-survival, doctor, gateway-start and gateway-probes.
    • The lane does not seed Telegram widget rows, because 2026.11.3 has none. The new rows use the namespaces telegram.widgets and telegram.widget-taps. Those names don't collide with the Telegram namespaces already on main (bot-info-cache, poll-registry, sticker-cache, update-offsets), so existing Telegram rows are never read or rewritten by this change.
  • Trial run against 92 widgets written by real models: 3 of them were really broken on Telegram.

    • Blocked: an element id used as a global, and overflow: auto.
    • Sent with a paint-limit note: 20 translucent cells that showed "Widget stopped". This one is now advisory, because the paint count is an approximation.
    • A poll state update that rendered undefined gets a note.
    • No other widget is blocked.
  • Trap prompts (sticky header, Chart.js, live price, text inputs, avatar URLs):

    • Models avoided almost every trap on their own.
    • On the sticky-header prompt, Haiku was rejected, fixed the widget and sent it.
  • Review fixes, each with a regression test:

    • a tap whose routing throws before dispatch is recorded as failed-retryable
    • a retryable dispatch outcome is passed to the ingress owner
    • a replay with the same query id is admitted; a new duplicate is still dropped
    • a sender outside the allowlist never reaches an agent turn
    • an empty state reaches the presenter as a clearing update, and the checker sees it as null
    • request().then(a => a.result) passes the trial run
    • literal "undefined" and "NaN" in content are accepted
    • when Telegram accepted a widget but its plugin-state record fails, the failure is logged and the send still reports success, so the model does not send it again
    • pin=true with Telegram-native widget code is refused before anything is written to the dashboard
    • with widgets unset or false, the presenter does not match and taps are dropped before any lookup or agent turn; /status shows both states
    • widgets are never sent into private topics, by string or numeric thread id
    • disabled buttons are not tapped; themeParams, viewer, TextEncoder and data GIFs work; CSS conditional rules and specificity follow the cascade
    • approximate findings are delivered as notes instead of blocking, and unmodeled web APIs skip the check
  • Checks: 167 tests pass across src/canvas and the Telegram widget suites. Typecheck is clean (tsgo:core, tsgo:extensions, tsgo:core:test, tsgo:extensions:test). The baseline ratchets, extension lint and boundary lint pass.

Screenshots

Telegram Web, dark theme, widgets sent by real models on the Telegram Test Server. All data is sample data. Light theme and mobile clients have not been checked yet.

PR list Gateway health
Open PRs widget Gateway health widget
Flight card with boarding countdown CI status board
Flight card widget CI board widget
ShellBench matrix in solid colors (the 20-translucent-cell version showed "Widget stopped"; the trial run now flags it to the model) Hotel picker after a tap (updated in place to "Chosen", no new message)
ShellBench matrix widget Hotel picker widget after tap

obviyus and others added 2 commits November 11, 2026 08:19
Telegram private chats get Bot API 10.4 message widgets from show_widget:
- core passes the agent-authored source, a stable widget name, and an
  optional state to channel presenters that declare it, and lets them
  replace the browser-host authoring rules
- widget taps become agent turns and state-only show_widget calls edit the
  tapped widget in place
- a QuickJS trial run returns script errors, removed content, unsupported
  CSS and Telegram stop limits to the model before anything is sent

Co-authored-by: obviyus <[email protected]>
OpenClaw-Publication: d1c37407-ba5d-496a-9e31-2084fd7304b4
@clawsweeper

clawsweeper Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: telegram Channel integration: telegram agents Agent runtime and tooling size: XL labels Nov 11, 2026
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. 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. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds opt-in interactive Telegram widgets through show_widget, with widget taps starting agent turns and updating state in place.

Example: A private-chat poll stores {"v":0}, and the user taps Vote.

  • Before: The agent uses text or an image without an interactive widget.
  • After: With channels.telegram.widgets=true, the poll updates to {"v":1} in the same Telegram message.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful feature with shipped-entry-point evidence, preserved defaults, and resolved prior findings; failing exact-head checks remain unattributed.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected Telegram screenshots show delivered widgets, and supplied real Gateway/Test Server results cover in-place tap updates, later-session use, allowed and denied senders, and the explicitly accepted post-admission revocation behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Telegram private-chat users cannot receive interactive show_widget cards and must use text or images.
Reason: The maintainer-authored direction provides demonstrated interactive value while keeping incompatible clients and other conversation surfaces on existing behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR adds a useful capability absent from main, and both prior blockers are resolved; two failing checks still need attribution.

Priority: P2
Reviewed head: bf6669b042530d17df6374fca3d86e0106f8f56b

Before merge

None.

Findings

None.

Agent review details

How this fits together

Core owns show_widget authoring and presentation selection; the Telegram plugin validates and sends widget code, admits incoming taps through existing authorization and ingress owners, and stores widget state through plugin-state storage.

flowchart LR
  Agent[Agent show_widget call] --> Core[Core widget tool]
  Core --> Presenter[Telegram presenter]
  Presenter --> Check[QuickJS trial run]
  Check --> Telegram[Telegram message widget]
  Telegram --> Ingress[Durable tap ingress]
  Ingress --> Auth[Telegram authorization]
  Auth --> Agent
Loading

Technical review

Best possible solution:

Keep the existing core presenter architecture and opt-in Telegram implementation, then resolve attribution of the failing checks before landing.

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

This is a new capability; inspected Telegram screenshots and supplied live Gateway results demonstrate rendering and interactive state updates.

Is this the best way to solve the issue?

The change uses the existing show_widget presenter, Telegram transport, durable ingress, authorization, and plugin-state owners; the channel-specific runtime justifies its adapter and bounded checker.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Core widget presentation ownership keeps the original intent (97557ec: fix(widgets): route show_widget through Discord Activities #126294 made core the sole show_widget owner and delegated channel-specific delivery to contextual presenters.)
  • Telegram rendering defaults keeps the original intent (a375d6c: fix(telegram): restore readable default text sends #93279 retained readable standard messages because older clients could not render richer accepted messages.)
  • Telegram update subscriptions keeps the original intent (160c34d: Subscribe only to supported behavior with an owning handler; this PR adds the widget-query handler while retaining the stopped-generation exclusion.)
  • Widget authoring guidance changes intended behavior with a stated reason (a7557f3: Existing guidance follows available presentation surfaces; the PR explains why Telegram-native code needs different runtime instructions and cannot be pinned into the browser shell.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Feature remains absent from main: Fetched main registers the Telegram Mini App but has no Telegram widget implementation; this PR supplies a distinct native-message capability. (extensions/telegram/index.ts:25, 8830ff6d8ed6)
  • Prior checker blockers resolved: Compared with the previous reviewed head, paint projections now produce advisory warnings, TextEncoder/TextDecoder are supplied, and accessing unmodeled web APIs makes the checker unavailable without blocking delivery. (extensions/telegram/src/widgets/widget-check-shim.ts:397, bf6669b04253)
  • Supplied production behavior proof: Directly inspected four downloaded Telegram screenshots showing rendered widgets; the PR records real Gateway/model tap updates, denied-sender final-effect results, and a published-upgrade-survivor run from 2026.11.3. (bf6669b04253)
  • Recorded authorization tradeoff: The maintainer-authored PR explicitly records that removal before tap admission prevents model turns, state changes, and new messages, while removal after admission allows the existing turn to finish, matching its ordinary-text control. (extensions/telegram/src/widgets/widget-query-router.ts:148, bf6669b04253)
  • Compatible default has established precedent: fix(telegram): restore readable default text sends #93279 restored readable standard Telegram messages and made richer client-dependent rendering opt-in; this PR follows that decision with widgets disabled by default. (extensions/telegram/src/widgets/widget-presenter.ts:85, a375d6c84963)
  • Exact-head CI requires attribution: checks-ui-e2e (2/4) fails at ui/src/e2e/sidebar-customization.e2e.test.ts:555; checks-node-compact-small-2 also fails with only an exit-code annotation. Job logs redirect to a storage host blocked by the network allowlist, so neither failure is attributed to this diff. (bf6669b04253)

PR surface

Source +2203, Tests +706, Docs +22, Config +8, Generated 0, Other +5. Total +2944 across 45 files. Added test files: 4.

View PR surface stats
Area Files Added Removed Net
Source 26 2217 14 +2203
Tests 9 713 7 +706
Docs 2 23 1 +22
Config 1 9 1 +8
Generated 5 10 10 0
Other 2 5 0 +5
Total 45 2977 33 +2944

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Configuration additions 2 optional boolean paths; default off Adds global and per-account widgets settings to preserve compatibility with older Telegram clients.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Useful optional Telegram capability with a limited, explicitly enabled private-chat surface.
  • merge-risk: 🚨 compatibility: Expands the plugin presenter contract and adds client-dependent rendering; the maintainer-authored direction accepts that expansion and preserves existing defaults.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

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 (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-11-11T04:05:39.845Z sha 1dc6fc0 :: blocked before merge. :: [P2] Preserve the successful receipt when widget bookkeeping fails
  • reviewed 2026-11-11T04:12:47.538Z sha 1dc6fc0 :: blocked before merge. :: [P2] Preserve the successful receipt when widget bookkeeping fails
  • reviewed 2026-11-11T04:25:13.561Z sha 843ccf6 :: blocked before merge. :: [P2] Keep Telegram-native code out of browser dashboard pins
  • reviewed 2026-11-11T05:28:14.674Z sha 789cdd0 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-11T06:08:46.657Z sha 6259f25 :: needs changes before merge. :: [P1] [P1] Exclude private-topic routes from the Telegram widget presenter | [P2] [P2] Migrate existing presenter callers to the required fields | [P2] [P2] Skip disabled buttons when simulating widget taps | [P2] [P2] Remove the new forbidden assertion chains
  • reviewed 2026-11-11T07:01:29.977Z sha 5d84635 :: needs changes before merge. :: [P2] [P2] Populate the documented widget runtime context | [P2] [P2] Avoid enforcing paint limits from an inaccurate CSS projection | [P2] [P2] Accept supported GIF data images
  • reviewed 2026-11-11T08:02:01.960Z sha b5f1e26 :: needs changes before merge. :: [P2] Preserve argument specificity for :is() and :not()
  • reviewed 2026-11-11T08:36:38.562Z sha 194fc10 :: needs changes before merge. :: [P2] Preserve declaration importance before enforcing paint limits | [P2] Provide supported guest APIs or classify their absence as checker failure

Reviewed November 11, 2026, 4:20 AM ET / 09:20 UTC (Revision 11).

obviyus and others added 2 commits November 11, 2026 08:50
- record failed-retryable when tap routing fails before dispatch or the
  dispatch itself is retryable, instead of tombstoning the acknowledged tap
- admit a durable replay of an already admitted query id
- always send widgets with allow_queries; the query router gates taps
- keep an explicitly empty show_widget state distinct from omission
- do not reject undefined/NaN the author wrote as text or string literals

Co-authored-by: obviyus <[email protected]>
OpenClaw-Publication: 5dbff3c5-52ad-48ed-8e45-b4ea4a8c46e9
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. and removed merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 11, 2026
obviyus and others added 2 commits November 11, 2026 09:10
… the trial run

- check an empty or missing state as null, as Telegram exposes it, while
  still sending the empty state to clear the widget
- resolve request() with { result: null } like Telegram's acknowledgment

Co-authored-by: obviyus <[email protected]>
OpenClaw-Publication: 2c2d8092-39e4-4a96-ba2e-586159fd75b0
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 11, 2026
obviyus and others added 2 commits November 11, 2026 15:25
OpenClaw-Publication: 5f1a4009-f666-4c2a-bc3e-f3fe53d120e7
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 11, 2026
@obviyus
obviyus merged commit b22f35f into main Nov 11, 2026
139 of 142 checks passed
@obviyus
obviyus deleted the openclaw/telegram-message-widgets branch November 11, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: discord Channel integration: discord channel: telegram Channel integration: telegram clawsweeper:intake:feature Preliminary submission classification; full source review pending. dependencies-changed PR changes dependency-related files docs Improvements or additions to documentation extensions: canvas merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

1 participant