ошибка создания креатива

This commit is contained in:
Artem Tsyrulnikov
2026-01-21 12:25:39 +03:00
parent 2c0dcbef97
commit a32bdc17d3

View File

@@ -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
}
// ВАЖНО: Сохраняем копию значения, а не указатель на переменную!