Skip to content

fix(telegram): route Markdown tables to rich messages - #1832

Open
key1989han wants to merge 1 commit into
felinics:mainfrom
key1989han:fix/telegram-markdown-table-rich
Open

key1989han wants to merge 1 commit into
felinics:mainfrom
key1989han:fix/telegram-markdown-table-rich

Conversation

@key1989han

Copy link
Copy Markdown

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

A Markdown table in an assistant reply reached Telegram as raw pipe-delimited text (| a | b | and |---|---| shown literally) instead of a rendered table. Plain prose in the same chat rendered fine, and adding a line of LaTeX math to the same message made the whole message — table included — render correctly, which located the problem in path selection rather than in the transport.

Two outbound paths exist for this channel. The rich path (sendRichMessage with InputRichMessage.markdown) renders tables, headings, checklists, and footnotes. The legacy path (formatTelegramOutput -> markdownToTelegramHTML with parseMode: HTML) has no table element at all, so table rows were passed through untouched. Selection in shouldUseTelegramFinalRichMessage and renderTelegramOutboundBody only consulted canonical Parts and LaTeX math, so a table-only message always fell through to the legacy path.

This change teaches the rich-path gate about Markdown tables and renames renderTelegramMarkdownMathRichMessage to renderTelegramMarkdownRichMessage to match its widened role. A table is detected as a header row immediately followed by a delimiter row of dashes with optional alignment colons, so stray pipes in prose or inline code are not misread. Messages with neither math nor a table keep using the legacy path, so nothing changes for the common case. The existing rich-length guard and plain-text fallback still apply.

Related Issues

Closes #1826

Validation

  • go test ./internal/channel/adapters/telegram/ passes on the patched tree, against current main (5db320a), including four new tests: TestTelegramMarkdownHasTable (positive cases with outer pipes, alignment colons, Persian header cells; negative cases for pipes in prose, a separator row without a header, a single-column separator, and plain prose), TestRenderTelegramMarkdownRichMessageTableRoutesToRich, TestRenderTelegramMarkdownRichMessagePlainTextStaysLegacy, and TestShouldUseTelegramFinalRichMessageForTable.
  • The full package suite was already green before the change and stays green after it.
  • Not run: mise run lint (golangci-lint) and the wider go test ./internal/... sweep, because the toolchain installed for this session only covers the affected package. The change is confined to one package and adds no new imports.

Screenshots / Recordings

No capture is available here: reproducing the visual difference needs a live Telegram bot channel and a Telegram client, and this session has neither a bot token nor browser access to Telegram clients. Verification is therefore the unit tests above plus the before/after screenshots already attached to #1826, which show the raw pipe rows and a correctly rendered table from the same Markdown source.

Human QA

  • Human QA passed

Telegram's legacy HTML parse mode has no table element, so a Markdown table sent through markdownToTelegramHTML reached the user as raw pipe-delimited rows. Only messages carrying canonical Parts or LaTeX math took the sendRichMessage path, which is the one that renders tables.

Detect a Markdown table (header row followed by a delimiter row) in the rich-path gate and rename renderTelegramMarkdownMathRichMessage to renderTelegramMarkdownRichMessage to match its widened role. Call sites in stream.go and telegram.go only change the name.
@github-actions github-actions Bot added bug Fixes a bug or unexpected behavior change:server Changes backend code, configuration, or API contracts size:S PR size uses the larger of added or deleted lines, excluding generated files labels Nov 23, 2026

This branch has not been deployed

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

Labels

bug Fixes a bug or unexpected behavior change:server Changes backend code, configuration, or API contracts size:S PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(telegram): render Markdown tables natively via rich messages

1 participant