Добавлен вывод кнопок для файлов
All checks were successful
CI / build-test (push) Successful in 31s
Release / pack-and-publish (release) Successful in 31s

This commit is contained in:
2025-12-07 08:26:45 +03:00
parent db122e8aef
commit d6f54bb0e6
6 changed files with 93 additions and 33 deletions

View File

@@ -85,11 +85,12 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup
}
/// <inheritdoc />
public async Task<string?> SendTextAsync(string chatId, string text, MessageFormat format,
IEnumerable<IEnumerable<InlineButton>>? inline,
IEnumerable<IEnumerable<ReplyButton>>? reply,
string? messageId,
CancellationToken ct)
public async Task<string?> SendTextAsync(string chatId, string text,
MessageFormat format = MessageFormat.Plain,
IEnumerable<IEnumerable<InlineButton>>? inline = null,
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
string? messageId = null,
CancellationToken ct = default)
{
if (_client is null)
{
@@ -187,7 +188,14 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup
}
/// <inheritdoc />
public async Task SendFileAsync(string chatId, FileDescriptor file, string? caption, MessageFormat? captionFormat, CancellationToken ct)
public async Task SendFileAsync(string chatId,
FileDescriptor file,
string? caption = null,
MessageFormat? captionFormat = null,
IEnumerable<IEnumerable<InlineButton>>? inline = null,
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
CancellationToken ct = default
)
{
if (_client is null)
{
@@ -249,20 +257,46 @@ public sealed class TelegramAdapter : IMessangerAdapterSetup
}
}
ReplyMarkup? markup = null;
if (inline is not null && inline.Any())
{
markup = new InlineKeyboardMarkup(
inline.Select(row => row.Select(b => new InlineKeyboardButton(b.Label, b.Value)).ToArray())
.ToArray()
);
}
else if (reply is not null)
{
if (reply.Any())
{
markup = new ReplyKeyboardMarkup(
reply.Select(row => row.Select(b => new KeyboardButton(b.Label)).ToArray()).ToArray()
)
{
ResizeKeyboard = true
};
}
else
{
markup = new ReplyKeyboardRemove();
}
}
// В зависимости от FileKind выбираем подходящий метод
switch (file.Kind)
{
case FileKind.Photo:
await _client.SendPhoto(long.Parse(chatId), inputFile, caption ?? "", parseMode, cancellationToken: ct);
await _client.SendPhoto(long.Parse(chatId), inputFile, caption ?? "", parseMode, replyMarkup: markup, cancellationToken: ct);
break;
case FileKind.Video:
await _client.SendVideo(long.Parse(chatId), inputFile, caption: caption ?? "", parseMode, cancellationToken: ct);
await _client.SendVideo(long.Parse(chatId), inputFile, caption: caption ?? "", parseMode, replyMarkup: markup, cancellationToken: ct);
break;
case FileKind.Audio:
await _client.SendAudio(long.Parse(chatId), inputFile, caption ?? "", parseMode, cancellationToken: ct);
await _client.SendAudio(long.Parse(chatId), inputFile, caption ?? "", parseMode, replyMarkup: markup, cancellationToken: ct);
break;
default:
await _client.SendDocument(long.Parse(chatId), inputFile, caption ?? "", parseMode, cancellationToken: ct);
await _client.SendDocument(long.Parse(chatId), inputFile, caption ?? "", parseMode, replyMarkup: markup, cancellationToken: ct);
break;
}
}