Skip to content

fix(telegram): fall back to plain text when HTML formatter produces empty output#17629

Closed
Glucksberg wants to merge 2 commits intoopenclaw:mainfrom
Glucksberg:fix/6652-telegram
Closed

fix(telegram): fall back to plain text when HTML formatter produces empty output#17629
Glucksberg wants to merge 2 commits intoopenclaw:mainfrom
Glucksberg:fix/6652-telegram

Conversation

@Glucksberg
Copy link
Contributor

@Glucksberg Glucksberg commented Feb 16, 2026

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 a 400: Bad Request: message text is empty error from the Telegram API, and the message is silently lost.

Fix Approach

Three layers of defense against empty HTML output:

  1. Auto-detect markdown tablesformat.ts now detects markdown table syntax (pipe-delimited rows with a divider line) and automatically applies tableMode: "code" to render them inside <pre><code> blocks instead of dropping them.

  2. ensureNonEmptyTelegramHtml() safety net — Both markdownToTelegramHtml() and markdownToTelegramChunks() now check if the rendered HTML is empty. If so, they fall back to HTML-escaped plain text, ensuring output is never silently empty.

  3. Delivery-level fallback — Both delivery.ts (bot mode) and send.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 both markdownToTelegramHtml and markdownToTelegramChunks
  • src/telegram/bot/delivery.ts — Pre-send empty HTML check with plain text fallback; refactored parse-error fallback to share params
  • src/telegram/send.ts — Same pre-send empty HTML check for the direct send path
  • src/telegram/format.test.ts — Tests for table auto-detection, empty-render fallback, and chunk fallback
  • src/telegram/bot/delivery.test.ts — Test for delivery-level empty HTML fallback

Test 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:

  • Auto-detects markdown tables and renders them in code blocks to prevent empty output
  • ensureNonEmptyTelegramHtml() fallback in format.ts returns HTML-escaped plain text when rendering produces empty output
  • Pre-send empty HTML checks in both delivery.ts and send.ts to send as plain text instead of failing with Telegram API error

The 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

  • This PR is safe to merge with minimal risk - it adds defensive fallback logic without breaking existing functionality
  • The changes are well-structured defensive programming that prevents message loss. The implementation includes comprehensive test coverage for the new fallback logic, maintains backward compatibility by only activating fallbacks when HTML is empty, and follows existing patterns in the codebase. The three-layer approach (table auto-detection, format-level fallback, delivery-level fallback) ensures robustness.
  • No files require special attention

Last reviewed commit: 0700167

@Glucksberg
Copy link
Contributor Author

Re-triage update with fresh repro on latest main:

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.

@Glucksberg
Copy link
Contributor Author

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.

@steipete
Copy link
Contributor

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.
Given that issue is closed, this fix PR is no longer needed in the active queue and is being closed as stale.

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.

@steipete steipete closed this Feb 24, 2026
obviyus pushed a commit to Glucksberg/OpenClaw that referenced this pull request Feb 24, 2026
…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.
obviyus pushed a commit that referenced this pull request Feb 24, 2026
…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.
margulans pushed a commit to margulans/Neiron-AI-assistant that referenced this pull request Feb 25, 2026
…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.
Jackson3195 pushed a commit to Jackson3195/openclaw-with-a-personal-touch that referenced this pull request Feb 25, 2026
…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.
brianleach pushed a commit to brianleach/openclaw that referenced this pull request Feb 26, 2026
…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.
execute008 pushed a commit to execute008/openclaw that referenced this pull request Feb 27, 2026
…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.
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
…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.
joelnishanth pushed a commit to joelnishanth/openclaw that referenced this pull request Mar 3, 2026
…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.
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: empty message sent when reply contains markdown tables

2 participants