Skip to content

fix(telegram): handle message too long errors from HTML table expansion#873

Open
chenhg5 wants to merge 1 commit into
mainfrom
fix/issue-866-telegram-message-too-long
Open

fix(telegram): handle message too long errors from HTML table expansion#873
chenhg5 wants to merge 1 commit into
mainfrom
fix/issue-866-telegram-message-too-long

Conversation

@chenhg5
Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 commented May 6, 2026

Summary

  • Handle "message is too long" error from Telegram when HTML table expansion exceeds 4096-char limit
  • Reply/Send: chunk the HTML content into multiple messages using SplitMessageCodeFenceAware
  • SendWithButtons: chunk with buttons attached only to the first message
  • SendPreviewStart: fall back to plain text (preview messages shouldn't be chunked)
  • Add sendChunked and sendChunkedWithButtons helper functions

Root Cause

The engine splits messages at 4000 chars based on Markdown length. But MarkdownToSimpleHTML() expands tables with column padding, causing the HTML output to exceed Telegram's actual 4096-char limit. Previously, this error was not handled, resulting in message drops.

Test plan

  • go build ./... passes
  • go vet ./... passes
  • go test ./... passes
  • Manual test needed: send a message with a wide Markdown table and verify it's chunked properly

Fixes #866

🤖 Generated with Claude Code

When Markdown tables are converted to HTML with column alignment padding,
the output can exceed Telegram's 4096-char limit even when the original
Markdown was under the engine's 4000-char split threshold.

Changes:
- Reply/Send: detect "message is too long" and chunk the HTML content
- SendWithButtons: chunk with buttons on first message only
- SendPreviewStart: fall back to plain text (preview shouldn't be chunked)
- Add sendChunked and sendChunkedWithButtons helper functions
- Use SplitMessageCodeFenceAware to respect code block boundaries

Fixes #866

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner Author

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

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

LGTM — targeted, correct fix for the Telegram 4096-char overflow edge case.

Root cause is correctly diagnosed: MarkdownToSimpleHTML() expands table columns with padding, so a message that fits Markdown's 4000-char budget can still exceed Telegram's actual 4096 HTML limit.

sendChunked/sendChunkedWithButtons — reuse existing core.SplitMessageCodeFenceAware, which already respects code block boundaries; correct choice.

sendChunkedWithButtons — buttons only on first chunk; avoids confusing "Submit" buttons appearing after the content they relate to.

Preview messages → plain-text fallback (not chunked). Correct: preview handles are tied to a single message ID; chunking would break the edit-in-place model.

Nested can't parse handler inside sendChunked — good defensive coding for malformed HTML in a chunk.

Consistent errMsg local variable across all 4 send methods (small style improvement).

CI all green.

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.

Telegram reply is dropped when Markdown table rendering expands below-limit responses past Telegram size limit

2 participants