fix(telegram): fall back to plain text when HTML formatter produces empty output#17629
fix(telegram): fall back to plain text when HTML formatter produces empty output#17629Glucksberg wants to merge 2 commits intoopenclaw:mainfrom
Conversation
|
Re-triage update with fresh repro on latest
This means the empty-text Telegram send failure path is still reachable on current main. Given this, I suggest we keep this PR (#17629) as the canonical fix path (superseding #17769) and re-evaluate with #25091 linked as fresh evidence. |
|
Update: we now have two explicit fix options for the same bug class:
Both are valid approaches; choice depends on preferred scope. If one option is selected for merge, the other can be closed (either by me or by the maintainer) to avoid duplicate maintenance. Fresh repro context is tracked in #25091. |
|
Closing as AI-assisted stale-fix triage. Linked issue #6652 ("Telegram: empty message sent when reply contains markdown tables") is currently closed and was closed on 2026-02-23T22:58:22Z with state reason completed. If this specific implementation is still needed on current main, please reopen #17629 (or open a new focused fix PR) and reference #6652 for fast re-triage. |
…empty Minimal fix path for Telegram empty-text failures in threaded replies. - fallback to plain text when formatted htmlText is empty - retry plain text on parse/empty-text API errors - add focused regression test for threaded mode case Related: openclaw#25091 Supersedes alternative fix path in openclaw#17629 if maintainers prefer minimal scope.
…empty Minimal fix path for Telegram empty-text failures in threaded replies. - fallback to plain text when formatted htmlText is empty - retry plain text on parse/empty-text API errors - add focused regression test for threaded mode case Related: #25091 Supersedes alternative fix path in #17629 if maintainers prefer minimal scope.
…empty Minimal fix path for Telegram empty-text failures in threaded replies. - fallback to plain text when formatted htmlText is empty - retry plain text on parse/empty-text API errors - add focused regression test for threaded mode case Related: openclaw#25091 Supersedes alternative fix path in openclaw#17629 if maintainers prefer minimal scope.
…empty Minimal fix path for Telegram empty-text failures in threaded replies. - fallback to plain text when formatted htmlText is empty - retry plain text on parse/empty-text API errors - add focused regression test for threaded mode case Related: openclaw#25091 Supersedes alternative fix path in openclaw#17629 if maintainers prefer minimal scope.
…empty Minimal fix path for Telegram empty-text failures in threaded replies. - fallback to plain text when formatted htmlText is empty - retry plain text on parse/empty-text API errors - add focused regression test for threaded mode case Related: openclaw#25091 Supersedes alternative fix path in openclaw#17629 if maintainers prefer minimal scope.
…empty Minimal fix path for Telegram empty-text failures in threaded replies. - fallback to plain text when formatted htmlText is empty - retry plain text on parse/empty-text API errors - add focused regression test for threaded mode case Related: openclaw#25091 Supersedes alternative fix path in openclaw#17629 if maintainers prefer minimal scope.
…empty Minimal fix path for Telegram empty-text failures in threaded replies. - fallback to plain text when formatted htmlText is empty - retry plain text on parse/empty-text API errors - add focused regression test for threaded mode case Related: openclaw#25091 Supersedes alternative fix path in openclaw#17629 if maintainers prefer minimal scope.
…empty Minimal fix path for Telegram empty-text failures in threaded replies. - fallback to plain text when formatted htmlText is empty - retry plain text on parse/empty-text API errors - add focused regression test for threaded mode case Related: openclaw#25091 Supersedes alternative fix path in openclaw#17629 if maintainers prefer minimal scope.
…empty Minimal fix path for Telegram empty-text failures in threaded replies. - fallback to plain text when formatted htmlText is empty - retry plain text on parse/empty-text API errors - add focused regression test for threaded mode case Related: openclaw#25091 Supersedes alternative fix path in openclaw#17629 if maintainers prefer minimal scope.
Fixes #6652
Problem
When a reply contains markdown tables or certain markdown constructs (e.g. bare
[]()links), the Telegram HTML formatter can produce empty output. This results in a400: Bad Request: message text is emptyerror from the Telegram API, and the message is silently lost.Fix Approach
Three layers of defense against empty HTML output:
Auto-detect markdown tables —
format.tsnow detects markdown table syntax (pipe-delimited rows with a divider line) and automatically appliestableMode: "code"to render them inside<pre><code>blocks instead of dropping them.ensureNonEmptyTelegramHtml()safety net — BothmarkdownToTelegramHtml()andmarkdownToTelegramChunks()now check if the rendered HTML is empty. If so, they fall back to HTML-escaped plain text, ensuring output is never silently empty.Delivery-level fallback — Both
delivery.ts(bot mode) andsend.ts(direct API mode) now check for empty HTML before calling the Telegram API. If detected, they send the message as unformatted plain text instead, logging a warning.Changed Files
src/telegram/format.ts— Added table auto-detection (hasMarkdownTableSyntax,resolveTelegramTableMode),ensureNonEmptyTelegramHtml()fallback, applied to bothmarkdownToTelegramHtmlandmarkdownToTelegramChunkssrc/telegram/bot/delivery.ts— Pre-send empty HTML check with plain text fallback; refactored parse-error fallback to share paramssrc/telegram/send.ts— Same pre-send empty HTML check for the direct send pathsrc/telegram/format.test.ts— Tests for table auto-detection, empty-render fallback, and chunk fallbacksrc/telegram/bot/delivery.test.ts— Test for delivery-level empty HTML fallbackTest Results
All 3 new test cases pass. 158 lines changed across 5 files.
Greptile Summary
Adds three-layer defense against empty HTML output from markdown formatter in Telegram integration:
ensureNonEmptyTelegramHtml()fallback informat.tsreturns HTML-escaped plain text when rendering produces empty outputdelivery.tsandsend.tsto send as plain text instead of failing with Telegram API errorThe fix comprehensively addresses the issue of messages being silently lost when markdown constructs like bare
[]()links or tables produce empty HTML, ensuring users always receive their messages.Confidence Score: 5/5
Last reviewed commit: 0700167