image
This commit is contained in:
@@ -10,6 +10,7 @@ public class Deal
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public long CreatedAtInMillis { get; set; }
|
||||
public string DealUrl { get; set; } = string.Empty;
|
||||
public string ImageMedium { get; set; } = string.Empty;
|
||||
public string Permalink { get; set; } = string.Empty;
|
||||
public string StoreName { get; set; } = string.Empty;
|
||||
public string StorePermalink { get; set; } = string.Empty;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user