fix(telegram): handle message too long errors from HTML table expansion#873
fix(telegram): handle message too long errors from HTML table expansion#873chenhg5 wants to merge 1 commit into
Conversation
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>
chenhg5
left a comment
There was a problem hiding this comment.
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.
Summary
SplitMessageCodeFenceAwaresendChunkedandsendChunkedWithButtonshelper functionsRoot 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 ./...passesgo vet ./...passesgo test ./...passesFixes #866
🤖 Generated with Claude Code