Skip to content

fix(telegram): preserve delivery without rich API - #92946

Closed
Glucksberg wants to merge 3 commits into
openclaw:mainfrom
Glucksberg:codex/telegram-rich-fallback
Closed

Glucksberg wants to merge 3 commits into
openclaw:mainfrom
Glucksberg:codex/telegram-rich-fallback

Conversation

@Glucksberg

@Glucksberg Glucksberg commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Preserves Telegram text delivery when rich Bot API methods are unavailable on a custom or lagging Bot API root.
  • Falls back from sendRichMessage / rich text edit to legacy sendMessage / editMessageText.
  • Re-chunks legacy fallback sends to Telegram's 4096-character text limit and avoids replaying already-delivered chunks when a later HTML chunk needs plain-text fallback.

Why this matters

OpenClaw's Telegram plugin now uses Telegram's newer rich Bot API methods for better formatting, but not every supported deployment reaches the official latest Bot API directly. Some users run through custom apiRoot deployments, self-hosted Bot API services, proxies, or lagging infrastructure where classic sendMessage still works but sendRichMessage does not exist yet.

Without this fallback, a formatting upgrade can turn into a message-delivery outage: ordinary text replies, edits, and stream previews can fail even though Telegram still supports the legacy send path. This PR keeps the new rich path as the preferred behavior while preserving basic Telegram delivery on older or custom Bot API surfaces, which is the safer compatibility posture for a channel plugin.

The fix stays local to the Telegram plugin, adds no new config surface, and follows Telegram's legacy 4096-character text contract so long replies do not fail after falling back.

Verification

  • node scripts/run-vitest.mjs extensions/telegram/src/network-errors.test.ts extensions/telegram/src/send.test.ts extensions/telegram/src/bot/delivery.test.ts extensions/telegram/src/draft-stream.test.ts
  • pnpm tsgo:extensions
  • pnpm tsgo:extensions:test
  • node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.extensions.json extensions/telegram/src/rich-message.ts extensions/telegram/src/network-errors.ts extensions/telegram/src/network-errors.test.ts extensions/telegram/src/send.ts extensions/telegram/src/send.test.ts extensions/telegram/src/bot/delivery.send.ts extensions/telegram/src/bot/delivery.test.ts extensions/telegram/src/draft-stream.ts extensions/telegram/src/draft-stream.test.ts
  • pnpm exec oxfmt --check --threads=1 extensions/telegram/src/rich-message.ts extensions/telegram/src/send.ts extensions/telegram/src/send.test.ts extensions/telegram/src/bot/delivery.send.ts extensions/telegram/src/bot/delivery.test.ts extensions/telegram/src/draft-stream.ts extensions/telegram/src/draft-stream.test.ts
  • git diff --check
  • .agents/skills/autoreview/scripts/autoreview --mode local

Real behavior proof

Behavior addressed: Telegram final text delivery still reaches a real Telegram user when the rich Bot API method is unavailable and OpenClaw has to fall back to legacy sendMessage.

Real environment tested: Local OpenClaw PR head 5558aed2d66a49d232e2c75e3c233b2f30e99a7e against a real Telegram bot and real Telegram user chat, using a local Bot API proxy that intentionally returns 404 for sendRichMessage while forwarding legacy sendMessage to Telegram's official Bot API.

Exact steps or command run after this patch:

node --import tsx .artifacts/manual-telegram-proof/rich-fallback-proof.ts proof

Evidence after fix:

# Telegram Rich Fallback Manual Proof

- PR: https://github.com/openclaw/openclaw/pull/92946
- Branch head: 5558aed2d66a49d232e2c75e3c233b2f30e99a7e
- Marker sent to Telegram: OPENCLAW-RICH-FALLBACK-2026-06-14T12:23:22.322Z
- Result: PASS

## Evidence

- Local Bot API proxy returned 404 for `sendRichMessage`.
- OpenClaw retried with legacy `sendMessage`.
- Telegram accepted the legacy message and returned a real `message_id`.
{
  "pass": true,
  "result": {
    "messageId": "5",
    "chatId": "[redacted]"
  },
  "proxyEvents": [
    {
      "method": "sendRichMessage",
      "richUnavailable": true,
      "status": 404
    },
    {
      "method": "sendMessage",
      "ok": true,
      "messageId": 5,
      "textLength": 54
    }
  ]
}

Observed result after fix: The local proxy rejected the rich Telegram method with 404, OpenClaw retried through legacy sendMessage, Telegram accepted the real API call, and the marker message appeared in the Telegram client.

What was not tested: This manual proof did not use the official Mantis/Crabbox burner-account workflow because the current contributor credentials cannot apply mantis: telegram-visible-proof or dispatch the maintainer-only workflow.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: M triage: blank-template Candidate: PR template appears mostly untouched. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 14, 2026
@clawsweeper

clawsweeper Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 22, 2026, 3:58 AM ET / 07:58 UTC.

Summary
The branch adds Telegram rich-method-unavailable fallback handling for direct sends, bot delivery, rich edits, draft previews, a shared error classifier, legacy 4096-character fallback chunking, and tests.

PR surface: Source +221, Tests +256. Total +477 across 9 files.

Reproducibility: yes. at source level: enable Telegram richMessages and use a Bot API root that rejects sendRichMessage; current main has no legacy fallback in the normal send, bot delivery, or preview paths. I did not run live Telegram in this read-only review.

Review metrics: 1 noteworthy metric.

  • Legacy fallback runtime surfaces: 5 changed. Direct sends, bot reply delivery, rich edits, preview sends, and preview edits all participate in the compatibility behavior maintainers need to validate before merge.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦪 silver shellfish
Patch quality: 🧂 unranked krab
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Fix the preview accounting and rich-error classifier blockers.
  • Define or scope long rich-edit fallback behavior with focused tests.
  • Update the PR body with redacted current-head Telegram proof, preferably including a long fallback case.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body includes redacted live Telegram logs for old head 5558aed2, but current head 5e3eb5c includes later fallback and chunking changes that are not covered. 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.

Mantis proof suggestion
Native Telegram proof would directly show whether rich-method-unavailable fallback preserves visible final text, especially for long replies and edit/preview paths. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: verify rich-method-unavailable fallback delivers visible Telegram text at current head, including a long reply without dropping the suffix.

Risk before merge

  • [P1] The rich-method-unavailable classifier can treat ordinary sendRichMessage 400 validation errors as a missing rich API and retry through legacy delivery, which can mask real Telegram rejections.
  • [P2] Long legacy preview fallback can visibly send only the first 4096-character slice while recording the full text as delivered, which can suppress the suffix during finalization.
  • [P2] Long rich edit fallback still routes full rich-sized text through legacy editMessageText, so old or custom Bot API roots can still fail instead of preserving delivery.
  • [P2] The supplied live Telegram proof is for an older branch head and short final delivery, not the current long fallback, preview, and edit behavior.

Maintainer options:

  1. Fix fallback semantics and refresh proof (recommended)
    Narrow the unavailable-method matcher, align preview accounting with visible legacy text, define long-edit behavior, and add redacted current-head Telegram proof before merge.
  2. Accept a narrower fallback scope
    Maintainers can intentionally scope this PR to short final sends only, but the PR body and tests should stop claiming broader preview, edit, and long-message preservation.
  3. Pause for a cleaner overlapping branch
    If another open Telegram fallback PR becomes proof-positive and cleaner first, pause or close this PR only after that replacement safely covers the same behavior.

Next step before merge

  • [P2] Manual follow-up is needed because the remaining blockers include stale contributor real-world proof and Telegram fallback semantics that automation cannot prove for the contributor's setup.

Security
Cleared: No concrete security or supply-chain regression was found; the diff stays within Telegram runtime/tests and does not change dependencies, workflows, secrets, permissions, package resolution, or downloads.

Review findings

  • [P1] Align legacy preview accounting with visible text — extensions/telegram/src/draft-stream.ts:142-148
  • [P2] Require method-not-found text before rich fallback — extensions/telegram/src/network-errors.ts:295
  • [P2] Define long rich-edit fallback behavior — extensions/telegram/src/send.ts:1682
Review details

Best possible solution:

Land one Telegram-plugin fallback that narrowly detects missing rich methods, keeps visible and recorded stream state aligned, defines long edit-limit behavior, and includes redacted current-head Telegram proof.

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

Yes, at source level: enable Telegram richMessages and use a Bot API root that rejects sendRichMessage; current main has no legacy fallback in the normal send, bot delivery, or preview paths. I did not run live Telegram in this read-only review.

Is this the best way to solve the issue?

No as submitted. The Telegram plugin is the right boundary, but this head needs narrower error classification, corrected long-preview accounting, defined long-edit behavior, and current-head real Telegram proof before it is the best fix.

Full review comments:

  • [P1] Align legacy preview accounting with visible text — extensions/telegram/src/draft-stream.ts:142-148
    When rich previews fall back, capTelegramLegacyTransportPreview sends at most the first legacy-sized chunk, but the caller still records the full requested text as delivered after success. A long reply can therefore make finalization skip the suffix; record only the visible slice or keep sending the remainder.
    Confidence: 0.94
  • [P2] Require method-not-found text before rich fallback — extensions/telegram/src/network-errors.ts:295
    This regex arm matches Call to 'sendRichMessage' failed! (400: before requiring method-not-found wording, so ordinary rich validation errors can be retried through legacy delivery as if the API method were missing. Restrict fallback to actual missing or unknown rich-method responses and add negative tests for non-method 400s.
    Confidence: 0.9
  • [P2] Define long rich-edit fallback behavior — extensions/telegram/src/send.ts:1682
    When rich edit is unavailable, the fallback sends the full rich-sized text through legacy editMessageText. Long rich edits can still fail on legacy Bot API roots unless the PR scopes edits to short text, truncates intentionally, switches to a follow-up send path, or rethrows with explicit tests.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d3f7f7d1fc91.

Label changes

Label justifications:

  • P2: This is a bounded Telegram delivery compatibility fix with real channel impact but limited blast radius.
  • merge-risk: 🚨 compatibility: The PR changes fallback and error-classification behavior for custom, proxied, self-hosted, or lagging Telegram Bot API roots.
  • merge-risk: 🚨 message-delivery: The current patch can suppress long preview suffixes, mask rich validation errors, or still fail long edit fallback on non-rich Bot API roots.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body includes redacted live Telegram logs for old head 5558aed2, but current head 5e3eb5c includes later fallback and chunking changes that are not covered. 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.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. This PR changes visible Telegram delivery, preview, and edit behavior that can be demonstrated in a short Telegram Desktop proof recording.
Evidence reviewed

PR surface:

Source +221, Tests +256. Total +477 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 313 92 +221
Tests 4 257 1 +256
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 570 93 +477

What I checked:

  • Repository policy applied: Root AGENTS.md, extensions/AGENTS.md, and the Telegram maintainer note were read; Telegram transport changes need real Telegram proof and fallback behavior is compatibility-sensitive. (.agents/maintainer-notes/telegram.md:37, d3f7f7d1fc91)
  • Current main lacks the fallback: Current main still routes rich text sends directly to sendTelegramRichTextChunks when richMessages is enabled, with no legacy sendMessage retry around missing rich methods. (extensions/telegram/src/send.ts:844, d3f7f7d1fc91)
  • Current bot delivery lacks the fallback: Current main returns directly from sendRichMessage for bot reply delivery when richMessages is enabled, so a missing rich method still aborts that delivery path. (extensions/telegram/src/bot/delivery.send.ts:124, d3f7f7d1fc91)
  • Current draft previews lack the fallback: Current main calls raw sendRichMessage/editMessageText in the rich draft preview send/edit paths without a legacy preview fallback when the rich API is unavailable. (extensions/telegram/src/draft-stream.ts:239, d3f7f7d1fc91)
  • PR head preview accounting blocker: At PR head, capTelegramLegacyTransportPreview caps legacy fallback previews to one legacy-sized chunk, while sendOrEditStreamMessage later records the full trimmed text as delivered after a successful send. (extensions/telegram/src/draft-stream.ts:131, 5e3eb5c47bd6)
  • PR head classifier blocker: The new unavailable-method regex accepts the generic sendRichMessage 400 wrapper before requiring missing-method wording; a focused Node probe confirmed that regex arm matches an ordinary sendRichMessage 400 message. (extensions/telegram/src/network-errors.ts:295, 5e3eb5c47bd6)

Likely related people:

  • obviyus: GitHub commit history shows this user introduced and expanded Telegram sendRichMessage/rich HTML behavior across send, delivery, draft, and rich-message helpers. (role: rich-message feature introducer and recent area contributor; confidence: high; commits: 547cc0f10903, da92615816b6, 663fabbe30eb; files: extensions/telegram/src/send.ts, extensions/telegram/src/bot/delivery.send.ts, extensions/telegram/src/draft-stream.ts)
  • NianJiuZst: Authored the merged opt-in richMessages compatibility gate that defines the current standard-vs-rich Telegram delivery boundary this PR extends. (role: recent rich-message compatibility contributor; confidence: high; commits: a375d6c84963; files: extensions/telegram/src/send.ts, extensions/telegram/src/draft-stream.ts, extensions/telegram/src/bot/delivery.send.ts)
  • chinar-amrutkar: Authored merged Telegram wrapped-error traversal and safe retry work in network-errors and send paths, which is the classifier boundary this PR modifies. (role: adjacent Telegram error-handling contributor; confidence: medium; commits: 3f67581e50a3; files: extensions/telegram/src/network-errors.ts, extensions/telegram/src/send.ts)
  • Nas01010101: Recent history shows this user worked on Telegram outbound chunker hardening adjacent to the legacy-limit chunking behavior touched here. (role: adjacent outbound chunking contributor; confidence: medium; commits: df87b40bec51; files: extensions/telegram/src/send.ts, extensions/telegram/src/rich-message.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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. labels Jun 14, 2026
@Glucksberg

Copy link
Copy Markdown
Contributor Author

@openclaw-mantis capture Telegram Desktop proof for this PR. Prefer proof that demonstrates final text delivery still reaches the real Telegram user from the PR branch when rich Bot API delivery is not available; if the harness cannot simulate a non-rich Bot API root, capture candidate real-user Telegram delivery on the PR branch and leave a concise manifest explaining the proof scope.

@Glucksberg

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated the PR head to re-chunk legacy Telegram fallback sends to the 4096-character Bot API text limit and avoid replaying already-delivered chunks when a later HTML fallback chunk needs plain text.

@clawsweeper

clawsweeper Bot commented Jun 14, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label Jun 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 14, 2026
@Glucksberg

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Real behavior proof has been added to the PR body. It includes a real Telegram bot/user run at PR head 5558aed2 with a local Bot API proxy returning 404 for sendRichMessage, followed by successful legacy sendMessage delivery with chat id redacted.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 14, 2026
@bonlime

bonlime commented Jun 15, 2026

Copy link
Copy Markdown

can you just update the bot api instance you're running? use-less PR IMO

@Glucksberg
Glucksberg force-pushed the codex/telegram-rich-fallback branch from 5558aed to 8fdfb71 Compare June 15, 2026 12:06
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 15, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 15, 2026
@clawsweeper clawsweeper Bot added the status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. label Jun 19, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jun 19, 2026
@Glucksberg
Glucksberg force-pushed the codex/telegram-rich-fallback branch from 2e782a0 to b6e3855 Compare June 20, 2026 06:38
@Glucksberg
Glucksberg force-pushed the codex/telegram-rich-fallback branch from b6e3855 to 0841f2f Compare June 20, 2026 06:41
@Glucksberg
Glucksberg force-pushed the codex/telegram-rich-fallback branch from 0841f2f to 19d7a7e Compare June 20, 2026 06:51
@Glucksberg
Glucksberg force-pushed the codex/telegram-rich-fallback branch from 19d7a7e to aa666c3 Compare June 20, 2026 06:52
@Glucksberg
Glucksberg force-pushed the codex/telegram-rich-fallback branch from aa666c3 to 42b6fd9 Compare June 20, 2026 06:55
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 20, 2026
@Glucksberg
Glucksberg force-pushed the codex/telegram-rich-fallback branch from 42b6fd9 to 2dbef8e Compare June 21, 2026 06:38
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jun 21, 2026
@Glucksberg
Glucksberg force-pushed the codex/telegram-rich-fallback branch from 2dbef8e to 92e3af1 Compare June 21, 2026 06:45
@bonlime

bonlime commented Jun 22, 2026

Copy link
Copy Markdown

richMessage is now behind a flag, what's the point of fallback? don't enable it if your client doesn't support

@Glucksberg

Copy link
Copy Markdown
Contributor Author

Closing this for now. Since rich messages are opt-in/default-off, I agree unsupported Bot API roots should avoid enabling them instead of depending on a fallback.

This implementation is also too broad: it can mask real rich-message errors, and the current proof does not cover the long/preview/edit delivery paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram mantis: telegram-visible-proof Mantis should capture Telegram visible proof. 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. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: blank-template Candidate: PR template appears mostly untouched.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants