From 2dccee5044665ed3a02bd19f4576654b22798fce Mon Sep 17 00:00:00 2001 From: I Putu Eddy Irawan Date: Sun, 1 Mar 2026 09:40:09 +0700 Subject: [PATCH] Address Copilot review feedback for Telegram message chunking - Add early return for empty content to avoid silent no-op - Split raw markdown before HTML conversion so SplitMessage's code-fence-aware logic works correctly and HTML tags/entities are never broken by mid-tag splitting Co-Authored-By: Claude Opus 4.6 --- pkg/channels/telegram/telegram.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/channels/telegram/telegram.go b/pkg/channels/telegram/telegram.go index ef0a1ef30..a28ae1bb9 100644 --- a/pkg/channels/telegram/telegram.go +++ b/pkg/channels/telegram/telegram.go @@ -173,14 +173,18 @@ func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) err return fmt.Errorf("invalid chat ID %s: %w", msg.ChatID, channels.ErrSendFailed) } - htmlContent := markdownToTelegramHTML(msg.Content) + if msg.Content == "" { + return nil + } - // Split HTML content into chunks that fit within Telegram's message limit. - // Use 4000 to leave headroom for HTML tag overhead beyond the 4096 limit. - chunks := channels.SplitMessage(htmlContent, 4000) + // Split the raw markdown before converting to HTML so that + // SplitMessage's code-fence-aware logic works correctly and + // we never break HTML tags/entities by splitting converted output. + mdChunks := channels.SplitMessage(msg.Content, 4000) - for _, chunk := range chunks { - tgMsg := tu.Message(tu.ID(chatID), chunk) + for _, chunk := range mdChunks { + htmlContent := markdownToTelegramHTML(chunk) + tgMsg := tu.Message(tu.ID(chatID), htmlContent) tgMsg.ParseMode = telego.ModeHTML if _, err = c.bot.SendMessage(ctx, tgMsg); err != nil {