From 308f1af33ae2421765b585d715e9cf286d3b51bb Mon Sep 17 00:00:00 2001 From: FrigaT Date: Fri, 5 Dec 2025 20:04:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D1=81=D0=BE?= =?UTF-8?q?=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B5=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BotPages.Telegram/TelegramAdapter.cs | 41 ++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/BotPages.Telegram/TelegramAdapter.cs b/BotPages.Telegram/TelegramAdapter.cs index 4334600..774956a 100644 --- a/BotPages.Telegram/TelegramAdapter.cs +++ b/BotPages.Telegram/TelegramAdapter.cs @@ -157,7 +157,7 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup } /// - public async Task SendFileAsync(string chatId, FileDescriptor file, string? caption, CancellationToken ct) + public async Task SendFileAsync(string chatId, FileDescriptor file, string? caption, MessageFormat? captionFormat, CancellationToken ct) { if (_client is null) { @@ -188,20 +188,51 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup inputFile = new InputFileId(file.Id); } + var parseMode = ParseMode.None; + + switch (captionFormat) + { + case MessageFormat.Html: + { + parseMode = ParseMode.Html; + break; + } + case MessageFormat.Plain: + { + parseMode = ParseMode.None; + break; + } + case MessageFormat.Markdown: + { + parseMode = ParseMode.MarkdownV2; + break; + } + case null: + { + parseMode = ParseMode.None; + break; + } + default: + { + _logger.Log(LogLevel.Warn, $"MessageFormat '{captionFormat}' not supported. Degraded to plain text."); + break; + } + } + // В зависимости от FileKind выбираем подходящий метод switch (file.Kind) { case FileKind.Photo: - await _client.SendPhoto(long.Parse(chatId), inputFile, caption ?? "", cancellationToken: ct); + await _client.SendPhoto(long.Parse(chatId), inputFile, caption ?? "", parseMode, cancellationToken: ct); break; case FileKind.Video: - await _client.SendVideo(long.Parse(chatId), inputFile, caption: caption ?? "", cancellationToken: ct); + await _client.SendVideo(long.Parse(chatId), inputFile, caption: caption ?? "", parseMode, cancellationToken: ct); break; case FileKind.Audio: - await _client.SendAudio(long.Parse(chatId), inputFile, caption ?? "", cancellationToken: ct); + await _client.SendAudio(long.Parse(chatId), inputFile, caption ?? "", parseMode, cancellationToken: ct); break; default: - await _client.SendDocument(long.Parse(chatId), inputFile, caption ?? "", cancellationToken: ct); + await _client.SendDocument(long.Parse(chatId), inputFile, caption ?? "", parseMode, cancellationToken: ct); break; } }