diff --git a/Telegrator/Handlers/MessageHandler.cs b/Telegrator/Handlers/MessageHandler.cs index b5ccef8..f840ee8 100644 --- a/Telegrator/Handlers/MessageHandler.cs +++ b/Telegrator/Handlers/MessageHandler.cs @@ -57,8 +57,8 @@ namespace Telegrator.Handlers string? businessConnectionId = null, bool allowPaidBroadcast = false, CancellationToken cancellationToken = default) - => await Client.SendMessage( - Input.Chat, text, parseMode, Input, + => await Container.Reply( + text, parseMode, replyMarkup, linkPreviewOptions, messageThreadId, entities, disableNotification, protectContent, @@ -96,8 +96,8 @@ namespace Telegrator.Handlers string? businessConnectionId = null, bool allowPaidBroadcast = false, CancellationToken cancellationToken = default) - => await Client.SendMessage( - Input.Chat, text, parseMode, replyParameters, + => await Container.Responce( + text, parseMode, replyParameters, replyMarkup, linkPreviewOptions, messageThreadId, entities, disableNotification, protectContent, @@ -140,8 +140,8 @@ namespace Telegrator.Handlers string? businessConnectionId = null, bool allowPaidBroadcast = false, CancellationToken cancellationToken = default) - => await Client.SendMessage( - Input.Chat, text, parseMode, Input, + => await Container.Reply( + text, parseMode, replyMarkup, linkPreviewOptions, messageThreadId, entities, disableNotification, protectContent, @@ -179,8 +179,8 @@ namespace Telegrator.Handlers string? businessConnectionId = null, bool allowPaidBroadcast = false, CancellationToken cancellationToken = default) - => await Client.SendMessage( - Input.Chat, text, parseMode, replyParameters, + => await Container.Responce( + text, parseMode, replyParameters, replyMarkup, linkPreviewOptions, messageThreadId, entities, disableNotification, protectContent, diff --git a/Telegrator/TypesExtensions.cs b/Telegrator/TypesExtensions.cs index 428a5fe..55b76be 100644 --- a/Telegrator/TypesExtensions.cs +++ b/Telegrator/TypesExtensions.cs @@ -1,13 +1,16 @@ using System.Collections; using System.Collections.ObjectModel; using System.Reflection; +using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Payments; +using Telegram.Bot.Types.ReplyMarkups; using Telegrator.Annotations; using Telegrator.Annotations.StateKeeping; using Telegrator.Attributes; using Telegrator.Filters.Components; +using Telegrator.Handlers; using Telegrator.Handlers.Building; using Telegrator.Handlers.Building.Components; using Telegrator.Handlers.Components; @@ -92,6 +95,92 @@ namespace Telegrator => StateKeeperAttribute.Shared; } + /// + /// Provides usefull helper methods for abstract handler containers + /// + public static class AbstractHandlerContainerExtensions + { + /// + /// Sends a reply message to the current message. + /// + /// + /// The text of the message to send. + /// The parse mode for the message text. + /// The reply markup for the message. + /// Options for link preview generation. + /// The thread ID for forum topics. + /// The message entities to include. + /// Whether to disable notification for the message. + /// Whether to protect the message content. + /// The message effect ID. + /// The business connection ID. + /// Whether to allow paid broadcast. + /// The cancellation token. + /// The sent message. + public static async Task Reply( + this IAbstractHandlerContainer container, + string text, + ParseMode parseMode = ParseMode.None, + ReplyMarkup? replyMarkup = null, + LinkPreviewOptions? linkPreviewOptions = null, + int? messageThreadId = null, + IEnumerable? entities = null, + bool disableNotification = false, + bool protectContent = false, + string? messageEffectId = null, + string? businessConnectionId = null, + bool allowPaidBroadcast = false, + CancellationToken cancellationToken = default) + => await container.Client.SendMessage( + container.ActualUpdate.Chat, text, parseMode, container.ActualUpdate, + replyMarkup, linkPreviewOptions, + messageThreadId, entities, + disableNotification, protectContent, + messageEffectId, businessConnectionId, + allowPaidBroadcast, cancellationToken); + + /// + /// Sends a response message to the current chat. + /// + /// + /// The text of the message to send. + /// The parse mode for the message text. + /// The reply parameters for the message. + /// The reply markup for the message. + /// Options for link preview generation. + /// The thread ID for forum topics. + /// The message entities to include. + /// Whether to disable notification for the message. + /// Whether to protect the message content. + /// The message effect ID. + /// The business connection ID. + /// Whether to allow paid broadcast. + /// The cancellation token. + /// The sent message. + public static async Task Responce( + this IAbstractHandlerContainer container, + string text, + ParseMode parseMode = ParseMode.None, + ReplyParameters? replyParameters = null, + ReplyMarkup? replyMarkup = null, + LinkPreviewOptions? linkPreviewOptions = null, + int? messageThreadId = null, + IEnumerable? entities = null, + bool disableNotification = false, + bool protectContent = false, + string? messageEffectId = null, + string? businessConnectionId = null, + bool allowPaidBroadcast = false, + CancellationToken cancellationToken = default) + => await container.Client.SendMessage( + container.ActualUpdate.Chat, text, parseMode, replyParameters, + replyMarkup, linkPreviewOptions, + messageThreadId, entities, + disableNotification, protectContent, + messageEffectId, businessConnectionId, + allowPaidBroadcast, cancellationToken); + } + /// /// Extensions methods for Awaiter Handler Builders ///