Добавлен формат сообщения при отправке документа
Some checks failed
CI / build-test (push) Failing after 36s
Release / pack-and-publish (release) Failing after 34s

This commit is contained in:
2025-12-05 20:04:42 +03:00
parent 5085958219
commit 308f1af33a

View File

@@ -157,7 +157,7 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup
} }
/// <inheritdoc /> /// <inheritdoc />
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) if (_client is null)
{ {
@@ -188,20 +188,51 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup
inputFile = new InputFileId(file.Id); 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 выбираем подходящий метод // В зависимости от FileKind выбираем подходящий метод
switch (file.Kind) switch (file.Kind)
{ {
case FileKind.Photo: 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; break;
case FileKind.Video: 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; break;
case FileKind.Audio: 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; break;
default: default:
await _client.SendDocument(long.Parse(chatId), inputFile, caption ?? "", cancellationToken: ct); await _client.SendDocument(long.Parse(chatId), inputFile, caption ?? "", parseMode, cancellationToken: ct);
break; break;
} }
} }