* Encapsulated "reply" and "respond" methods into extension methods for the container class
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<TKey, TState, TKeeper>.Shared;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides usefull helper methods for abstract handler containers
|
||||
/// </summary>
|
||||
public static class AbstractHandlerContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends a reply message to the current message.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="text">The text of the message to send.</param>
|
||||
/// <param name="parseMode">The parse mode for the message text.</param>
|
||||
/// <param name="replyMarkup">The reply markup for the message.</param>
|
||||
/// <param name="linkPreviewOptions">Options for link preview generation.</param>
|
||||
/// <param name="messageThreadId">The thread ID for forum topics.</param>
|
||||
/// <param name="entities">The message entities to include.</param>
|
||||
/// <param name="disableNotification">Whether to disable notification for the message.</param>
|
||||
/// <param name="protectContent">Whether to protect the message content.</param>
|
||||
/// <param name="messageEffectId">The message effect ID.</param>
|
||||
/// <param name="businessConnectionId">The business connection ID.</param>
|
||||
/// <param name="allowPaidBroadcast">Whether to allow paid broadcast.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>The sent message.</returns>
|
||||
public static async Task<Message> Reply(
|
||||
this IAbstractHandlerContainer<Message> container,
|
||||
string text,
|
||||
ParseMode parseMode = ParseMode.None,
|
||||
ReplyMarkup? replyMarkup = null,
|
||||
LinkPreviewOptions? linkPreviewOptions = null,
|
||||
int? messageThreadId = null,
|
||||
IEnumerable<MessageEntity>? 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);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a response message to the current chat.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="text">The text of the message to send.</param>
|
||||
/// <param name="parseMode">The parse mode for the message text.</param>
|
||||
/// <param name="replyParameters">The reply parameters for the message.</param>
|
||||
/// <param name="replyMarkup">The reply markup for the message.</param>
|
||||
/// <param name="linkPreviewOptions">Options for link preview generation.</param>
|
||||
/// <param name="messageThreadId">The thread ID for forum topics.</param>
|
||||
/// <param name="entities">The message entities to include.</param>
|
||||
/// <param name="disableNotification">Whether to disable notification for the message.</param>
|
||||
/// <param name="protectContent">Whether to protect the message content.</param>
|
||||
/// <param name="messageEffectId">The message effect ID.</param>
|
||||
/// <param name="businessConnectionId">The business connection ID.</param>
|
||||
/// <param name="allowPaidBroadcast">Whether to allow paid broadcast.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>The sent message.</returns>
|
||||
public static async Task<Message> Responce(
|
||||
this IAbstractHandlerContainer<Message> container,
|
||||
string text,
|
||||
ParseMode parseMode = ParseMode.None,
|
||||
ReplyParameters? replyParameters = null,
|
||||
ReplyMarkup? replyMarkup = null,
|
||||
LinkPreviewOptions? linkPreviewOptions = null,
|
||||
int? messageThreadId = null,
|
||||
IEnumerable<MessageEntity>? 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extensions methods for Awaiter Handler Builders
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user