Repository navigation
Description
Author
Agent
Type
bug
Bug Description
A Markdown table in an assistant reply is delivered to Telegram as raw pipe-delimited text (| a | b | and |---|---| shown literally) instead of a rendered table. Plain prose and other Markdown in the same chat render correctly, so the problem is limited to tables.
Memoh already calls Telegram's rich-message API, and that API does support tables, so the transport is capable. The defect is in path selection: a message only takes the rich path when it carries canonical Parts or LaTeX math, and a table-only message carries neither.
The workaround that isolates the bug: adding a line of math to the same message (for example $$E = mc^2$$) makes the whole message render correctly, table included.
Steps to Reproduce
-
Connect a bot to a Telegram chat channel in Memoh.
-
Send an assistant reply whose body is only a Markdown table, for example:
# item status 1 text message done -
Observe the delivered message in the Telegram client: the pipes and the delimiter row arrive as plain text, with no table rendered.
-
Add a line containing
$$E = mc^2$$to the end of the same reply and send it again: the table now renders.
Expected and Actual Behavior
Expected: the table renders as a table, the same way it does in the Memoh web and desktop clients, because Telegram's rich messages support tables.
Actual: the table arrives as raw pipe-delimited rows. The legacy HTML parse mode has no table element, so nothing converts the rows, and they pass through untouched.
Version
Memoh main at commit 5db320a ("chore: Go 1.27.4 and golangci-lint 2.15.0; lint the whole module; drop dead tests and CI entries (#1831)"), checked out 2026-11-23. Telegram transport: internal/channel/adapters/telegram. The same behavior is present on the released build used by the reporting workspace.
Environment
Self-hosted Memoh server; Telegram Bot API channel; a Telegram desktop client on Windows. No local Bot API server, no proxy.
Model Used
Not specific to the model: reproduced with more than one backend. The shape of the outbound message is what decides the path, not which model produced it.
Logs
No error is logged. The rich send is never attempted, because shouldUseTelegramFinalRichMessage returns false for a table-only message, so this is a silent fall-through to the legacy HTML path rather than a failure.
Screenshots / Recordings
Screenshots are attached in the linked report but I cannot attach new ones from this session: reproducing the visual difference needs a live Telegram bot channel, and this session has no bot token and no browser access to a Telegram client. Alternative verification is in Additional Context: a unit test asserts path selection for table Markdown, and the full package suite passes.
Additional Context
Root cause. Two outbound paths exist in internal/channel/adapters/telegram:
- Rich path:
sendRichMessagewithInputRichMessage.markdown(rich_transport.go). This renders tables, headings, checklists, and footnotes. - Legacy path:
formatTelegramOutput->markdownToTelegramHTML(markdown.go) withparseMode: HTML. Its regex set covers bold, italic, strike, links, inline code, fenced blocks, and headings only. Legacy Telegram HTML has no table element.
Selection happens in shouldUseTelegramFinalRichMessage (stream.go) and renderTelegramOutboundBody (telegram.go):
func shouldUseTelegramFinalRichMessage(msg channel.Message) bool {
return len(msg.Parts) > 0 || renderTelegramMarkdownMathRichMessage(msg).hasContent()
}and the helper gates on math only:
if !telegramMarkdownHasMath(markdown) {
return telegramInputRichMessage{}
}Proposed Solution
Teach the rich-path gate about Markdown tables, and rename the helper to match its widened role:
func renderTelegramMarkdownRichMessage(msg channel.Message) telegramInputRichMessage {
...
if !telegramMarkdownHasMath(markdown) && !telegramMarkdownHasTable(markdown) {
return telegramInputRichMessage{}
}
return telegramInputRichMessage{Markdown: markdown}
}with a detector that requires a header row immediately followed by a delimiter row, so stray pipes in prose or inline code are not misread:
func telegramMarkdownHasTable(text string) bool {
lines := strings.Split(text, "\n")
for i := 1; i < len(lines); i++ {
if isTelegramMarkdownTableDelimiterRow(lines[i]) && isTelegramMarkdownTableRow(lines[i-1]) {
return true
}
}
return false
}Delimiter validation accepts ---, :---, ---:, and :---:, and requires at least two cells. Messages with neither math nor a table keep using the legacy path, so the common case is unchanged, and the existing rich-length guard and plain-text fallback still apply.
A pull request implements this: #1832. It adds markdown_table_test.go with TestTelegramMarkdownHasTable, TestRenderTelegramMarkdownRichMessageTableRoutesToRich, TestRenderTelegramMarkdownRichMessagePlainTextStaysLegacy, and TestShouldUseTelegramFinalRichMessageForTable; go test ./internal/channel/adapters/telegram/ passes on the patched tree.
Alternatives Considered
- Wrap tables in a fenced code block. Aligns columns in monospace, but gives no header weight, no wrapping on mobile, and Persian content breaks under bidi inside a code block. A workaround, not a fix.
- Render the table as an image. Works everywhere, but costs an upload per message, loses selectable text, and is unusable for long tables.
- Keep a hidden math line in the message to force the rich path. Fragile: it renders visibly as a formula and depends on an unrelated heuristic.
Activity
github-actions commentedon Nov 21, 2026
Format check passed; removed
needs:format.