From 3de4cb863babcf3077ea6c8a35a5ade31b00962f Mon Sep 17 00:00:00 2001 From: I Putu Eddy Irawan Date: Wed, 4 Mar 2026 22:15:17 +0700 Subject: [PATCH] fix: pass original markdown to sendHTMLChunk for plain-text fallback When HTML parsing fails, the fallback was re-sending the same HTML string with ParseMode cleared, showing raw HTML tags to users. Now pass the original markdown chunk so the fallback displays readable plain text instead. Co-Authored-By: Claude Opus 4.6 --- pkg/channels/telegram/telegram.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/channels/telegram/telegram.go b/pkg/channels/telegram/telegram.go index 3dece4700..fe1167bd1 100644 --- a/pkg/channels/telegram/telegram.go +++ b/pkg/channels/telegram/telegram.go @@ -255,14 +255,14 @@ func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) err } subChunks := channels.SplitMessage(chunk, smallerLen) for _, sub := range subChunks { - if err := c.sendHTMLChunk(ctx, chatID, markdownToTelegramHTML(sub)); err != nil { + if err := c.sendHTMLChunk(ctx, chatID, markdownToTelegramHTML(sub), sub); err != nil { return err } } continue } - if err := c.sendHTMLChunk(ctx, chatID, htmlContent); err != nil { + if err := c.sendHTMLChunk(ctx, chatID, htmlContent, chunk); err != nil { return err } } @@ -270,8 +270,9 @@ func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) err return nil } -// sendHTMLChunk sends a single HTML message, falling back to plain text on parse failure. -func (c *TelegramChannel) sendHTMLChunk(ctx context.Context, chatID int64, htmlContent string) error { +// sendHTMLChunk sends a single HTML message, falling back to the original +// markdown as plain text on parse failure so users never see raw HTML tags. +func (c *TelegramChannel) sendHTMLChunk(ctx context.Context, chatID int64, htmlContent, mdFallback string) error { tgMsg := tu.Message(tu.ID(chatID), htmlContent) tgMsg.ParseMode = telego.ModeHTML @@ -279,6 +280,7 @@ func (c *TelegramChannel) sendHTMLChunk(ctx context.Context, chatID int64, htmlC logger.ErrorCF("telegram", "HTML parse failed, falling back to plain text", map[string]any{ "error": err.Error(), }) + tgMsg.Text = mdFallback tgMsg.ParseMode = "" if _, err = c.bot.SendMessage(ctx, tgMsg); err != nil { return fmt.Errorf("telegram send: %w", channels.ErrTemporary)