Skip to content

fix(telegram): render markdown as Telegram HTML with safe, telegram-only fallbacks#126

Merged
jamiepine merged 4 commits intospacedriveapp:mainfrom
bilawalriaz:codex/telegram-fix-upstream-clean
Feb 22, 2026
Merged

fix(telegram): render markdown as Telegram HTML with safe, telegram-only fallbacks#126
jamiepine merged 4 commits intospacedriveapp:mainfrom
bilawalriaz:codex/telegram-fix-upstream-clean

Conversation

@bilawalriaz
Copy link
Copy Markdown
Contributor

Summary

Telegram responses were being delivered as unrendered markdown. This PR adds Telegram-native HTML formatting and hardens fallback behavior so messages/files are still delivered reliably when Telegram rejects formatting.

What Changed

  • Updated Telegram text send paths to use formatted sends (ParseMode::Html) in src/messaging/telegram.rs.
  • Added markdown-to-Telegram-HTML conversion helpers for common formatting:
    • bold/italic/strikethrough
    • links
    • inline/fenced code
    • headings and blockquotes
    • HTML escaping
  • Added robust formatted-message chunking to avoid breaking HTML tags across Telegram’s 4096-char limit.
  • Added plain-text fallback when formatted message send/edit fails.
  • Added file caption formatting for Telegram documents.
  • Hardened file caption fallback:
    • Retry plain caption only on Telegram parse-entity errors (CantParseEntities).
    • Do not retry on non-parse errors (prevents duplicate file sends).

Scope / Safety

  • Telegram-only change.
  • No behavior change for Slack, Discord, or other messaging adapters.

Tests

  • Added/extended unit tests in src/messaging/telegram.rs for formatting conversion and parse-error retry gating.

Convert markdown output to Telegram-compatible HTML before sending,
so bold, italic, code, links, headers, blockquotes and code blocks
render properly instead of showing raw markdown characters.

Every send path (text, rich messages, thread replies, streaming edits,
captions, ephemeral, scheduled, broadcast) now goes through
`send_formatted` which sets `ParseMode::Html` and automatically falls
back to plain text if the API rejects the HTML.

Only the Telegram adapter is touched — Discord and Slack are unaffected.
If Telegram rejects the HTML caption the file was silently lost.
Now retry with the raw caption text so the document is always delivered.
Copy link
Copy Markdown
Member

@jamiepine jamiepine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@jamiepine jamiepine merged commit 7a80047 into spacedriveapp:main Feb 22, 2026
0 of 3 checks passed
@bilawalriaz bilawalriaz deleted the codex/telegram-fix-upstream-clean branch February 22, 2026 21:28
rktmeister pushed a commit to rktmeister/spacebot that referenced this pull request Mar 11, 2026
…fix-upstream-clean

fix(telegram): render markdown as Telegram HTML with safe, telegram-only fallbacks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants