From a32bdc17d3d30e991e79b6f939b0100a5fedc83d Mon Sep 17 00:00:00 2001 From: Artem Tsyrulnikov Date: Wed, 21 Jan 2026 12:25:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BA=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tg_bot/screens/creative_editor.go | 43 +++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tg_bot/screens/creative_editor.go b/tg_bot/screens/creative_editor.go index 79cffca..8d68378 100644 --- a/tg_bot/screens/creative_editor.go +++ b/tg_bot/screens/creative_editor.go @@ -73,6 +73,7 @@ const msgCreativeManagement = ` Выберите, что изменить: ` +const msgCreativePreviewBroken = "⚠️ Не удалось показать превью: креатив содержит некорректную разметку. Создайте его заново или отредактируйте текст." func buildCreativeKeyboard(buttons [][]echotron.InlineKeyboardButton) echotron.InlineKeyboardMarkup { keyboard := echotron.InlineKeyboardMarkup{ @@ -84,6 +85,14 @@ func buildCreativeKeyboard(buttons [][]echotron.InlineKeyboardButton) echotron.I return keyboard } +func isTelegramParseError(err error) bool { + if err == nil { + return false + } + msg := err.Error() + return strings.Contains(msg, "can't parse entities") || strings.Contains(msg, "Unexpected end tag") +} + // GetCreativeText возвращает текст для превью креатива func (e *CreativeEditorFields) GetCreativeText() string { if e.Text == nil { @@ -162,6 +171,21 @@ func (e *CreativeEditorFields) SendCreativePreview(b *bot.Bot) { } return res.Result.ID, nil } + sendFallback := func() (int, error) { + res, err := b.SendMessage(msgCreativePreviewBroken, b.ChatID, &echotron.MessageOptions{ + ReplyMarkup: keyboard, + LinkPreviewOptions: echotron.LinkPreviewOptions{ + IsDisabled: true, + }, + }) + if err != nil { + return 0, err + } + if res.Result == nil { + return 0, fmt.Errorf("send message: empty result") + } + return res.Result.ID, nil + } // Если есть медиа, отправляем с медиа if e.MediaFileID != "" { @@ -206,6 +230,10 @@ func (e *CreativeEditorFields) SendCreativePreview(b *bot.Bot) { // Fallback to text message - используем прямой SendMessage if id, err := sendText(); err == nil { msgID = id + } else if isTelegramParseError(err) { + if id, err := sendFallback(); err == nil { + msgID = id + } } } else if res.Result != nil { msgID = res.Result.ID @@ -216,9 +244,20 @@ func (e *CreativeEditorFields) SendCreativePreview(b *bot.Bot) { id, err := sendText() if err != nil { log.Error().Err(err).Msg("Failed to send creative preview") - return + if isTelegramParseError(err) { + id, err = sendFallback() + if err == nil { + msgID = id + } else { + log.Error().Err(err).Msg("Failed to send fallback creative preview") + return + } + } else { + return + } + } else { + msgID = id } - msgID = id } // ВАЖНО: Сохраняем копию значения, а не указатель на переменную!