This commit is contained in:
kislovdm
2026-03-11 09:03:34 +03:00
parent 900d9b2c61
commit fbe18bbb77
3 changed files with 38 additions and 1 deletions
@@ -81,6 +81,7 @@ public class PepperClient : IPepperClient
CreatedAt = dto.CreatedAt ?? DateTimeOffset.FromUnixTimeMilliseconds(dto.CreatedAtInMillis).UtcDateTime,
CreatedAtInMillis = dto.CreatedAtInMillis,
DealUrl = dto.DealUrl ?? string.Empty,
ImageMedium = dto.ImageMedium ?? string.Empty,
Permalink = dto.Permalink ?? string.Empty,
StoreName = dto.Store?.Name ?? string.Empty,
StorePermalink = dto.Store?.Permalink ?? string.Empty
@@ -119,6 +120,9 @@ public class PepperClient : IPepperClient
[JsonPropertyName("deal_url")]
public string? DealUrl { get; set; }
[JsonPropertyName("image_medium")]
public string? ImageMedium { get; set; }
[JsonPropertyName("permalink")]
public string? Permalink { get; set; }
@@ -288,9 +288,22 @@ public class TelegramNotifier : ITelegramNotifier
try
{
var text = textBuilder.ToString();
if (!string.IsNullOrWhiteSpace(deal.ImageMedium)
&& Uri.TryCreate(deal.ImageMedium, UriKind.Absolute, out var imageUri))
{
await _botClient.SendPhoto(
chatId: chatId,
photo: InputFile.FromUri(imageUri),
caption: text,
cancellationToken: cancellationToken);
return;
}
await _botClient.SendMessage(
chatId: chatId,
text: textBuilder.ToString(),
text: text,
cancellationToken: cancellationToken);
}
catch (ApiRequestException ex)
@@ -301,6 +314,25 @@ public class TelegramNotifier : ITelegramNotifier
chatId,
ex.ErrorCode,
ex.Message);
// Фолбэк: если фото не отправилось (например, Telegram не смог скачать URL),
// пробуем хотя бы текст.
try
{
await _botClient.SendMessage(
chatId: chatId,
text: textBuilder.ToString(),
cancellationToken: cancellationToken);
}
catch (ApiRequestException fallbackEx)
{
Logger.Warn(
fallbackEx,
"Не удалось отправить фолбэк-текст в Telegram (чат {ChatId}): [{Code}] {Message}",
chatId,
fallbackEx.ErrorCode,
fallbackEx.Message);
}
}
}