2 Commits

Author SHA1 Message Date
8af03fa52b исправлена подпись
All checks were successful
CI / build-test (push) Successful in 30s
Release / pack-and-publish (release) Successful in 31s
2025-12-07 08:41:03 +03:00
d6f54bb0e6 Добавлен вывод кнопок для файлов
All checks were successful
CI / build-test (push) Successful in 31s
Release / pack-and-publish (release) Successful in 31s
2025-12-07 08:26:45 +03:00
7 changed files with 108 additions and 36 deletions

View File

@@ -9,22 +9,33 @@ namespace BotPages.Core.Abstractions;
/// </summary>
public interface IMessengerAdapter
{
/// <summary>
/// Доступные возможности мессенджера.
/// </summary>
Capabilities Capabilities { get; }
/// <summary>
/// Отправить текстовое сообщение в чат.
/// </summary>
Task<string?> SendTextAsync(string chatId, string text, MessageFormat format,
IEnumerable<IEnumerable<InlineButton>>? inline,
IEnumerable<IEnumerable<ReplyButton>>? reply,
string? messageId,
CancellationToken ct
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
);
/// <summary>
/// Отправить файл в чат.
/// </summary>
Task SendFileAsync(string chatId, FileDescriptor file, string? caption, MessageFormat? captionFormat, CancellationToken ct);
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);
/// <summary>
/// Создать билдер альбома для отправки медиагруппы.

View File

@@ -11,7 +11,9 @@ public static class PageContextAdapterExtensions
/// <summary>
/// Отправить текстовое сообщение.
/// </summary>
public static Task<string?> SendTextAsync(this PageContext ctx, string text, MessageFormat format = MessageFormat.Plain,
public static Task<string?> SendTextAsync(this PageContext ctx,
string text,
MessageFormat format = MessageFormat.Plain,
IEnumerable<IEnumerable<InlineButton>>? inline = null,
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
string? messageId = null,
@@ -21,12 +23,19 @@ public static class PageContextAdapterExtensions
/// <summary>
/// Отправить файл.
/// </summary>
public static Task SendFileAsync(this PageContext ctx, FileDescriptor file, string? caption = null, MessageFormat? captionFormat = null, CancellationToken ct = default)
=> ctx.Adapter.SendFileAsync(ctx.Update.Chat.Id, file, caption, captionFormat, ct);
/// <summary>
/// Отправить файл.
/// </summary>
public static Task SendFileAsync(this PageContext ctx, FileDescriptor file, string? caption = null, CancellationToken ct = default)
=> ctx.Adapter.SendFileAsync(ctx.Update.Chat.Id, file, caption, null, ct);
public static Task SendFileAsync(this PageContext ctx,
FileDescriptor file,
string? caption = null,
MessageFormat? captionFormat = null,
IEnumerable<IEnumerable<InlineButton>>? inline = null,
IEnumerable<IEnumerable<ReplyButton>>? reply = null,
CancellationToken ct = default
)
=> ctx.Adapter.SendFileAsync(chatId: ctx.Update.Chat.Id,
file: file,
caption: caption,
captionFormat: captionFormat,
inline: inline,
reply: reply,
ct: ct);
}

View File

@@ -123,19 +123,25 @@ public sealed class MessageBuilder
{
string? messageId = null;
List<List<ReplyButton>>? reply = null;
if (_disableReplyKeyboard) reply = new();
else if (_reply.Any()) reply = _reply;
// Текст
if (!string.IsNullOrWhiteSpace(_text))
{
List<List<ReplyButton>>? reply = null;
if (_disableReplyKeyboard) reply = new();
else if (_reply.Any()) reply = _reply;
messageId = await _ctx.SendTextAsync(_text, _format, _inline, reply, _editMessageId, ct);
}
// Файлы
foreach (var (file, caption, captionFormat) in _files)
await _ctx.SendFileAsync(file, caption, captionFormat, ct);
await _ctx.SendFileAsync(file: file
, caption: caption
, captionFormat: captionFormat
, reply: reply
, inline: _inline
, ct: ct
);
// Альбом
if (_album.Count > 0)

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;
}
}

View File

@@ -53,7 +53,7 @@ public sealed class TelegramAlbumBuilder : IAlbumBuilder
{
_logger.Log(LogLevel.Warn, "Albums not supported. Degraded to sequential sends.");
foreach (var (file, caption, captionFormat) in _items)
await _adapter.SendFileAsync(_ctx.Update.Chat.Id, file, caption, captionFormat, ct);
await _adapter.SendFileAsync(_ctx.Update.Chat.Id, file, caption, captionFormat, ct: ct);
return;
}
@@ -95,7 +95,7 @@ public sealed class TelegramAlbumBuilder : IAlbumBuilder
{
// Telegram не поддерживает document в альбомах — деградация
_logger.Log(LogLevel.Warn, $"Document '{file.Kind}' in album not supported. Sending document separately.");
await _adapter.SendFileAsync(_ctx.Update.Chat.Id, file, caption, captionFormat, ct);
await _adapter.SendFileAsync(_ctx.Update.Chat.Id, file, caption, captionFormat, ct: ct);
}
}

View File

@@ -1,9 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>BotPages</PackageId>
<Version>1.0.0</Version>
<Authors>FrigaT</Authors>
<Company>FrigaT</Company>
<Product>BotPages</Product>
<Description>Платформонезависимый framework для создания диалоговых ботов с системой страниц.</Description>
<Copyright>Copyright © 2025 FrigaT</Copyright>
<RepositoryUrl>https://git.frigat.duckdns.org/FrigaT/BotPages</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://git.frigat.duckdns.org/FrigaT/BotPages</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
<ItemGroup>

View File

@@ -20,7 +20,7 @@ public sealed class FilesPage : SingletonPage
{
foreach (var file in files)
{
await ctx.SendFileAsync(file, $"Файл '{file.Name}' получен и отправлен обратно.", ct);
await ctx.SendFileAsync(file, $"Файл '{file.Name}' получен и отправлен обратно.", ct: ct);
}
//Обращение через Storage