From 4fa140d91f10a9284a7ceaa8e28329befd16a3f5 Mon Sep 17 00:00:00 2001 From: FrigaT Date: Wed, 11 Feb 2026 00:39:58 +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=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=86=D0=B2=D0=B5=D1=82=D0=BE=D0=B2=20=D0=BA=D0=BD?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D0=BA=20=D1=82=D0=B5=D0=BB=D0=B5=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BotPages.Core/Messaging/InlineButton.cs | 5 +++++ BotPages.Core/Messaging/ReplyButton.cs | 21 +++++++++++++++++++ BotPages.Telegram/BotPages.Telegram.csproj | 2 +- BotPages.Telegram/TelegramAdapter.cs | 24 ++++++++++++++++++++-- Demo/Pages/WelcomePage.cs | 2 +- Demo/Program.cs | 4 ++-- 6 files changed, 52 insertions(+), 6 deletions(-) diff --git a/BotPages.Core/Messaging/InlineButton.cs b/BotPages.Core/Messaging/InlineButton.cs index b161669..f0c0d5e 100644 --- a/BotPages.Core/Messaging/InlineButton.cs +++ b/BotPages.Core/Messaging/InlineButton.cs @@ -22,6 +22,11 @@ public class InlineButton this.Value = value; } + /// + /// Стиль кнопки. + /// + public ButtonStyle Style { get; set; } = ButtonStyle.Default; + /// public InlineButton(Enum value) { diff --git a/BotPages.Core/Messaging/ReplyButton.cs b/BotPages.Core/Messaging/ReplyButton.cs index ff7f608..62cf2bf 100644 --- a/BotPages.Core/Messaging/ReplyButton.cs +++ b/BotPages.Core/Messaging/ReplyButton.cs @@ -22,6 +22,11 @@ public class ReplyButton this.Label = value.GetButtonLabel(); } + /// + /// Стиль кнопки. + /// + public ButtonStyle Style { get; set; } = ButtonStyle.Default; + /// /// Преобразование строки к кнопке. /// @@ -34,3 +39,19 @@ public class ReplyButton /// public static implicit operator ReplyButton(Enum en) => new ReplyButton(en); } + + +/// +/// Стиль оформления сообщения. +/// +public enum ButtonStyle +{ + /// Обычный стиль. + Default, + /// Стиль информационого сообщения. + Info, + /// Стиль успеха. + Success, + /// Стиль ошибки. + Error, +} \ No newline at end of file diff --git a/BotPages.Telegram/BotPages.Telegram.csproj b/BotPages.Telegram/BotPages.Telegram.csproj index 772f4ab..dbd6b90 100644 --- a/BotPages.Telegram/BotPages.Telegram.csproj +++ b/BotPages.Telegram/BotPages.Telegram.csproj @@ -14,7 +14,7 @@ - + diff --git a/BotPages.Telegram/TelegramAdapter.cs b/BotPages.Telegram/TelegramAdapter.cs index 2608a06..85ca267 100644 --- a/BotPages.Telegram/TelegramAdapter.cs +++ b/BotPages.Telegram/TelegramAdapter.cs @@ -375,7 +375,17 @@ public sealed class TelegramAdapter : IMessengerAdapterSetup { if (inline is null || !inline.Any()) return null; return new InlineKeyboardMarkup( - inline.Select(row => row.Select(b => new InlineKeyboardButton(b.Label, b.Value)).ToArray()).ToArray() + inline.Select(row => row.Select(b => new InlineKeyboardButton(b.Label, b.Value) + { + Style = b.Style switch + { + ButtonStyle.Default => null, + ButtonStyle.Info => KeyboardButtonStyle.Primary, + ButtonStyle.Error => KeyboardButtonStyle.Danger, + ButtonStyle.Success => KeyboardButtonStyle.Success, + _ => null, + } + }).ToArray()).ToArray() ); } @@ -385,7 +395,17 @@ public sealed class TelegramAdapter : IMessengerAdapterSetup if (reply.Any()) { - return new ReplyKeyboardMarkup(reply.Select(row => row.Select(b => new KeyboardButton(b.Label)).ToArray()).ToArray()) + return new ReplyKeyboardMarkup(reply.Select(row => row.Select(b => new KeyboardButton(b.Label) + { + Style = b.Style switch + { + ButtonStyle.Default => null, + ButtonStyle.Info => KeyboardButtonStyle.Primary, + ButtonStyle.Error => KeyboardButtonStyle.Danger, + ButtonStyle.Success => KeyboardButtonStyle.Success, + _ => null, + } + }).ToArray()).ToArray()) { ResizeKeyboard = true }; diff --git a/Demo/Pages/WelcomePage.cs b/Demo/Pages/WelcomePage.cs index c145460..547bbd3 100644 --- a/Demo/Pages/WelcomePage.cs +++ b/Demo/Pages/WelcomePage.cs @@ -33,7 +33,7 @@ public sealed class WelcomePage : SingletonPage return ctx.Navigation.GoToAsync(ctx, ct); case WelcomePageButtons.Help: - return new MessageBuilder(ctx).Text("Здесь будет справка.", MessageFormat.Plain).SendAsync(ct); + return new MessageBuilder(ctx).Text("Здесь будет справка.", MessageFormat.Plain).Style(MessageStyle.Success).SendAsync(ct); case WelcomePageButtons.SendFile: return ctx.Navigation.GoToAsync(ctx, ct); diff --git a/Demo/Program.cs b/Demo/Program.cs index 28c85aa..b772b3f 100644 --- a/Demo/Program.cs +++ b/Demo/Program.cs @@ -45,9 +45,9 @@ namespace Demo .MapCommand("/open {page}", openHandler, true, "открыть страницу /open {page}") .MapCommand(DetailsPage.Command, DetailsPage.CommandHandler, true, DetailsPage.CommandDescription) .AutoMapRoute() + .AddTelegramAdapter(token, "Telegram") .AddMiddleware(new ErrorHandlingMiddleware(logger)) - .AddMiddleware(new LoggingMiddleware(logger)) - .AddTelegramAdapter(token, "Telegram"); + .AddMiddleware(new LoggingMiddleware(logger)); await app.RunAsync();