diff --git a/src/Navigator/Actions/BotAction.cs b/src/Navigator/Actions/BotAction.cs index 327733b..ba374d6 100644 --- a/src/Navigator/Actions/BotAction.cs +++ b/src/Navigator/Actions/BotAction.cs @@ -1,7 +1,7 @@ namespace Navigator.Actions; /// -/// A is a representation of an action that can be executed by a navigator bot. It is used to encapsulate a +/// A is ah representation of an action that can be executed by a navigator bot. It is used to encapsulate a /// condition and a handler. The condition is a delegate that is checked at runtime and if it evaluates to true, the handler is executed. /// The condition delegate should return a boolean or a Task that resolves to a boolean. The handler delegate should return void or a Task /// that resolves to void. diff --git a/src/Navigator/Actions/BotActionInformation.cs b/src/Navigator/Actions/BotActionInformation.cs index 2fcd141..4e7de24 100644 --- a/src/Navigator/Actions/BotActionInformation.cs +++ b/src/Navigator/Actions/BotActionInformation.cs @@ -1,3 +1,5 @@ +using Telegram.Bot.Types.Enums; + namespace Navigator.Actions; /// @@ -10,6 +12,11 @@ public record BotActionInformation /// public required UpdateCategory Category; + /// + /// The associtated with the . Optional. + /// + public required ChatAction? ChatAction; + /// /// The input types of the condition delegate of the . /// @@ -25,6 +32,11 @@ public record BotActionInformation /// public required Type[] HandlerInputTypes; + /// + /// The name of the . If no name is set, the id is used. + /// + public required string Name; + /// /// The priority of the . Optional. /// diff --git a/src/Navigator/Actions/Builder/BotActionBuilder.cs b/src/Navigator/Actions/Builder/BotActionBuilder.cs index 597afd8..f016025 100644 --- a/src/Navigator/Actions/Builder/BotActionBuilder.cs +++ b/src/Navigator/Actions/Builder/BotActionBuilder.cs @@ -1,3 +1,5 @@ +using Telegram.Bot.Types.Enums; + namespace Navigator.Actions.Builder; /// @@ -5,39 +7,26 @@ namespace Navigator.Actions.Builder; /// public class BotActionBuilder { - private readonly Delegate _condition; - private readonly Type[] _conditionInputTypes; - private readonly Delegate _handler; - private readonly Type[] _handlerInputTypes; private readonly Guid _id; /// /// Initializes a new instance of the class. /// - /// - /// A delegate representing the condition under which the handler should be invoked. - /// Must return or where TResult is . - /// - /// - /// A delegate representing the action to take when the condition is met. - /// - public BotActionBuilder(Delegate condition, Delegate handler) + public BotActionBuilder() { _id = Guid.NewGuid(); - - if (!(condition.Method.ReturnType != typeof(Task) || condition.Method.ReturnType != typeof(bool))) - throw new NavigatorException("The condition delegate must return Task or bool"); - - _condition = condition; - _conditionInputTypes = condition.Method.GetParameters().Select(info => info.ParameterType).ToArray(); - _handler = handler; - _handlerInputTypes = handler.Method.GetParameters().Select(info => info.ParameterType).ToArray(); Priority = Actions.Priority.Default; } + private string? Name { get; set; } + private Delegate? Condition { get; set; } + private Type[] ConditionInputTypes { get; set; } = null!; + private Delegate? Handler { get; set; } + private Type[] HandlerInputTypes { get; set; } = null!; private UpdateCategory Category { get; set; } = null!; private ushort Priority { get; set; } private TimeSpan? Cooldown { get; set; } + private ChatAction? ChatAction { get; set; } /// /// Builds the bot action. @@ -47,14 +36,74 @@ public BotAction Build() { var information = new BotActionInformation { + ChatAction = ChatAction, Category = Category, - ConditionInputTypes = _conditionInputTypes, - HandlerInputTypes = _handlerInputTypes, + ConditionInputTypes = ConditionInputTypes, + HandlerInputTypes = HandlerInputTypes, + Name = Name ?? $"{_id}", Priority = Priority, Cooldown = Cooldown }; - return new BotAction(_id, information, _condition, _handler); + if (Condition is null || Handler is null) + throw new NavigatorException("Both condition and handler must be set"); + + if (!(Condition.Method.ReturnType != typeof(Task) || Condition.Method.ReturnType != typeof(bool))) + throw new NavigatorException("The condition delegate must return Task or bool"); + + if (Category is null) + throw new NavigatorException("The category must be set"); + + return new BotAction(_id, information, Condition, Handler); + } + + /// + /// Sets the name of the . + /// + /// The name to be set. + /// An instance of to be able to continue configuring the . + public BotActionBuilder WithName(string name) + { + Name = name; + + return this; + } + + /// + /// Sets the condition of the . + /// + /// The condition to be set. + /// An instance of to be able to continue configuring the . + public BotActionBuilder SetCondition(Delegate condition) + { + Condition = condition; + ConditionInputTypes = condition.Method.GetParameters().Select(info => info.ParameterType).ToArray(); + + return this; + } + + /// + /// Sets the handler of the . + /// + /// The handler to be set. + /// An instance of to be able to continue configuring the . + public BotActionBuilder SetHandler(Delegate handler) + { + Handler = handler; + HandlerInputTypes = handler.Method.GetParameters().Select(info => info.ParameterType).ToArray(); + + return this; + } + + /// + /// Sets the of the . + /// + /// The to be set. + /// An instance of to be able to continue configuring the . + public BotActionBuilder SetCategory(UpdateCategory category) + { + Category = category; + return this; } /// @@ -80,13 +129,14 @@ public BotActionBuilder WithCooldown(TimeSpan cooldown) } /// - /// Sets the of the . + /// Sets the of the . /// - /// The to be set. + /// The to be set. /// An instance of to be able to continue configuring the . - public BotActionBuilder SetCategory(UpdateCategory category) + public BotActionBuilder WithChatAction(ChatAction chatAction) { - Category = category; + ChatAction = chatAction; + return this; } } \ No newline at end of file diff --git a/src/Navigator/Catalog/Factory/BotActionCatalogFactory.cs b/src/Navigator/Catalog/Factory/BotActionCatalogFactory.cs index 59ba6d2..7f36d9f 100644 --- a/src/Navigator/Catalog/Factory/BotActionCatalogFactory.cs +++ b/src/Navigator/Catalog/Factory/BotActionCatalogFactory.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using Navigator.Actions; using Navigator.Actions.Builder; using Telegram.Bot.Types.Enums; @@ -9,6 +10,17 @@ namespace Navigator.Catalog.Factory; /// public class BotActionCatalogFactory { + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + /// An instance of . + public BotActionCatalogFactory(ILogger logger) + { + _logger = logger; + } + private List Actions { get; } = []; private BotActionCatalog? Catalog { get; set; } @@ -22,12 +34,14 @@ public class BotActionCatalogFactory /// /// A delegate representing the action to take when the condition is met. /// - public BotActionBuilder OnUpdate(Delegate condition, Delegate handler) + public BotActionBuilder OnUpdate(Delegate condition, Delegate? handler = default) { - var id = Guid.NewGuid(); - var actionBuilder = new BotActionBuilder(condition, handler); + var actionBuilder = new BotActionBuilder(); - actionBuilder.SetCategory(new UpdateCategory(nameof(UpdateType), nameof(UpdateType.Unknown))); + actionBuilder + .SetCondition(condition) + .SetHandler(handler ?? (Action)(() => { })) + .SetCategory(new UpdateCategory(nameof(UpdateType), nameof(UpdateType.Unknown))); Actions.Add(actionBuilder); @@ -50,9 +64,17 @@ public BotActionCatalog Retrieve() /// private void Build() { - var actions = Actions - .Select(actionBuilder => actionBuilder.Build()) - .ToList(); + _logger.LogInformation("Building BotActionCatalog with {ActionsCount} actions", Actions.Count); + + var actions = new List(); + + foreach (var builtAction in Actions.Select(actionBuilder => actionBuilder.Build())) + { + _logger.LogDebug("Built action {ActionName} with priority {Priority} for category {Category}", + builtAction.Information.Name, builtAction.Information.Priority, builtAction.Information.Category); + + actions.Add(builtAction); + } Catalog = new BotActionCatalog(actions); } diff --git a/src/Navigator/Catalog/Factory/Extensions/BotActionCatalogFactoryExtensions.cs b/src/Navigator/Catalog/Factory/Extensions/BotActionCatalogFactoryExtensions.cs index 2e5cfa2..fb581f0 100644 --- a/src/Navigator/Catalog/Factory/Extensions/BotActionCatalogFactoryExtensions.cs +++ b/src/Navigator/Catalog/Factory/Extensions/BotActionCatalogFactoryExtensions.cs @@ -49,7 +49,8 @@ public static class BotActionCatalogFactoryExtensions /// /// /// Configures a new bot action to respond to any which includes one - /// event using the specified handler delegate. + /// event using the specified handler delegate. It also sets the action name to the + /// command string starting with /. /// /// /// Additionally, this method can be replaced with or for more advanced @@ -60,18 +61,21 @@ public static class BotActionCatalogFactoryExtensions /// An instance of /// The specific command string that this action should respond to. /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// /// /// - public static BotActionBuilder OnCommand(this BotActionCatalogFactory factory, string command, Delegate handler) + public static BotActionBuilder OnCommand(this BotActionCatalogFactory factory, string command, Delegate? handler = default) { var actionBuilder = factory.OnUpdate((Update update) => update.Message?.ExtractCommand() == command, handler); - actionBuilder.SetCategory(new UpdateCategory(nameof(MessageType), nameof(MessageEntityType.BotCommand))); + actionBuilder + .WithName($"/{command}") + .SetCategory(new UpdateCategory(nameof(MessageType), nameof(MessageEntityType.BotCommand))); return actionBuilder; } @@ -86,13 +90,14 @@ public static BotActionBuilder OnCommand(this BotActionCatalogFactory factory, s /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// /// - public static BotActionBuilder OnMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -111,12 +116,13 @@ public static BotActionBuilder OnMessage(this BotActionCatalogFactory factory, D /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnText(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnText(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -135,12 +141,13 @@ public static BotActionBuilder OnText(this BotActionCatalogFactory factory, Dele /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnPhoto(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnPhoto(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -159,12 +166,13 @@ public static BotActionBuilder OnPhoto(this BotActionCatalogFactory factory, Del /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnAudio(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnAudio(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -183,12 +191,13 @@ public static BotActionBuilder OnAudio(this BotActionCatalogFactory factory, Del /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnVideo(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnVideo(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -207,12 +216,13 @@ public static BotActionBuilder OnVideo(this BotActionCatalogFactory factory, Del /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnVoice(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnVoice(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -231,12 +241,13 @@ public static BotActionBuilder OnVoice(this BotActionCatalogFactory factory, Del /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnDocument(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnDocument(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -255,12 +266,13 @@ public static BotActionBuilder OnDocument(this BotActionCatalogFactory factory, /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnSticker(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnSticker(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -279,12 +291,13 @@ public static BotActionBuilder OnSticker(this BotActionCatalogFactory factory, D /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnLocation(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnLocation(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -303,12 +316,13 @@ public static BotActionBuilder OnLocation(this BotActionCatalogFactory factory, /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnContact(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnContact(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -327,12 +341,13 @@ public static BotActionBuilder OnContact(this BotActionCatalogFactory factory, D /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnVenue(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnVenue(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -351,12 +366,13 @@ public static BotActionBuilder OnVenue(this BotActionCatalogFactory factory, Del /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnGame(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnGame(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -375,12 +391,13 @@ public static BotActionBuilder OnGame(this BotActionCatalogFactory factory, Dele /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnVideoNote(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnVideoNote(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -399,12 +416,13 @@ public static BotActionBuilder OnVideoNote(this BotActionCatalogFactory factory, /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnInvoice(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnInvoice(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -423,12 +441,14 @@ public static BotActionBuilder OnInvoice(this BotActionCatalogFactory factory, D /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnSuccessfulPayment(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnSuccessfulPayment(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -447,12 +467,13 @@ public static BotActionBuilder OnSuccessfulPayment(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnConnectedWebsite(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnConnectedWebsite(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -471,12 +492,13 @@ public static BotActionBuilder OnConnectedWebsite(this BotActionCatalogFactory f /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnNewChatMembers(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnNewChatMembers(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -495,12 +517,13 @@ public static BotActionBuilder OnNewChatMembers(this BotActionCatalogFactory fac /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnLeftChatMember(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnLeftChatMember(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -519,12 +542,13 @@ public static BotActionBuilder OnLeftChatMember(this BotActionCatalogFactory fac /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnNewChatTitle(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnNewChatTitle(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -543,12 +567,13 @@ public static BotActionBuilder OnNewChatTitle(this BotActionCatalogFactory facto /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnNewChatPhoto(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnNewChatPhoto(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -567,12 +592,13 @@ public static BotActionBuilder OnNewChatPhoto(this BotActionCatalogFactory facto /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnPinnedMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnPinnedMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -591,12 +617,13 @@ public static BotActionBuilder OnPinnedMessage(this BotActionCatalogFactory fact /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnDeleteChatPhoto(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnDeleteChatPhoto(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -615,12 +642,13 @@ public static BotActionBuilder OnDeleteChatPhoto(this BotActionCatalogFactory fa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnGroupChatCreated(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnGroupChatCreated(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -639,13 +667,14 @@ public static BotActionBuilder OnGroupChatCreated(this BotActionCatalogFactory f /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// public static BotActionBuilder OnSupergroupChatCreated(this BotActionCatalogFactory factory, Delegate condition, - Delegate handler) + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -664,12 +693,14 @@ public static BotActionBuilder OnSupergroupChatCreated(this BotActionCatalogFact /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnChannelChatCreated(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnChannelChatCreated(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -688,12 +719,14 @@ public static BotActionBuilder OnChannelChatCreated(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnMigrateFromChatId(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnMigrateFromChatId(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -712,12 +745,13 @@ public static BotActionBuilder OnMigrateFromChatId(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnMigrateToChatId(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnMigrateToChatId(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -736,12 +770,13 @@ public static BotActionBuilder OnMigrateToChatId(this BotActionCatalogFactory fa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnPollMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnPollMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -760,12 +795,13 @@ public static BotActionBuilder OnPollMessage(this BotActionCatalogFactory factor /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnDice(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnDice(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -785,13 +821,14 @@ public static BotActionBuilder OnDice(this BotActionCatalogFactory factory, Dele /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// public static BotActionBuilder OnMessageAutoDeleteTimerChanged(this BotActionCatalogFactory factory, Delegate condition, - Delegate handler) + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -810,13 +847,14 @@ public static BotActionBuilder OnMessageAutoDeleteTimerChanged(this BotActionCat /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// public static BotActionBuilder OnProximityAlertTriggered(this BotActionCatalogFactory factory, Delegate condition, - Delegate handler) + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -835,12 +873,13 @@ public static BotActionBuilder OnProximityAlertTriggered(this BotActionCatalogFa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnWebAppData(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnWebAppData(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -859,12 +898,14 @@ public static BotActionBuilder OnWebAppData(this BotActionCatalogFactory factory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnVideoChatScheduled(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnVideoChatScheduled(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -883,12 +924,13 @@ public static BotActionBuilder OnVideoChatScheduled(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnVideoChatStarted(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnVideoChatStarted(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -907,12 +949,13 @@ public static BotActionBuilder OnVideoChatStarted(this BotActionCatalogFactory f /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnVideoChatEnded(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnVideoChatEnded(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -932,13 +975,14 @@ public static BotActionBuilder OnVideoChatEnded(this BotActionCatalogFactory fac /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// public static BotActionBuilder OnVideoChatParticipantsInvited(this BotActionCatalogFactory factory, Delegate condition, - Delegate handler) + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -957,12 +1001,13 @@ public static BotActionBuilder OnVideoChatParticipantsInvited(this BotActionCata /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnAnimation(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnAnimation(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -981,12 +1026,14 @@ public static BotActionBuilder OnAnimation(this BotActionCatalogFactory factory, /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnForumTopicCreated(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnForumTopicCreated(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1005,12 +1052,13 @@ public static BotActionBuilder OnForumTopicCreated(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnForumTopicClosed(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnForumTopicClosed(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1029,12 +1077,14 @@ public static BotActionBuilder OnForumTopicClosed(this BotActionCatalogFactory f /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnForumTopicReopened(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnForumTopicReopened(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1053,12 +1103,13 @@ public static BotActionBuilder OnForumTopicReopened(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnForumTopicEdited(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnForumTopicEdited(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1077,12 +1128,14 @@ public static BotActionBuilder OnForumTopicEdited(this BotActionCatalogFactory f /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnGeneralForumTopicHidden(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnGeneralForumTopicHidden(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1101,12 +1154,14 @@ public static BotActionBuilder OnGeneralForumTopicHidden(this BotActionCatalogFa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnGeneralForumTopicUnhidden(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnGeneralForumTopicUnhidden(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1125,12 +1180,14 @@ public static BotActionBuilder OnGeneralForumTopicUnhidden(this BotActionCatalog /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnWriteAccessAllowed(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnWriteAccessAllowed(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1149,12 +1206,13 @@ public static BotActionBuilder OnWriteAccessAllowed(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnUsersShared(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnUsersShared(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1173,12 +1231,13 @@ public static BotActionBuilder OnUsersShared(this BotActionCatalogFactory factor /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnChatShared(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnChatShared(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1197,12 +1256,13 @@ public static BotActionBuilder OnChatShared(this BotActionCatalogFactory factory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnPassportData(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnPassportData(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1221,12 +1281,13 @@ public static BotActionBuilder OnPassportData(this BotActionCatalogFactory facto /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnGiveawayCreated(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnGiveawayCreated(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1245,12 +1306,13 @@ public static BotActionBuilder OnGiveawayCreated(this BotActionCatalogFactory fa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnGiveaway(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnGiveaway(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1269,12 +1331,13 @@ public static BotActionBuilder OnGiveaway(this BotActionCatalogFactory factory, /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnGiveawayWinners(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnGiveawayWinners(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1293,12 +1356,14 @@ public static BotActionBuilder OnGiveawayWinners(this BotActionCatalogFactory fa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnGiveawayCompleted(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnGiveawayCompleted(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1317,12 +1382,13 @@ public static BotActionBuilder OnGiveawayCompleted(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnBoostAdded(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnBoostAdded(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1341,12 +1407,14 @@ public static BotActionBuilder OnBoostAdded(this BotActionCatalogFactory factory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnChatBackgroundSet(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnChatBackgroundSet(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1365,12 +1433,13 @@ public static BotActionBuilder OnChatBackgroundSet(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnPaidMedia(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnPaidMedia(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1389,12 +1458,13 @@ public static BotActionBuilder OnPaidMedia(this BotActionCatalogFactory factory, /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnRefundedPayment(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnRefundedPayment(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1413,12 +1483,13 @@ public static BotActionBuilder OnRefundedPayment(this BotActionCatalogFactory fa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnUnknownMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnUnknownMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1436,12 +1507,13 @@ public static BotActionBuilder OnUnknownMessage(this BotActionCatalogFactory fac /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnInlineQuery(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnInlineQuery(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1459,12 +1531,14 @@ public static BotActionBuilder OnInlineQuery(this BotActionCatalogFactory factor /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnChosenInlineResult(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnChosenInlineResult(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1482,12 +1556,13 @@ public static BotActionBuilder OnChosenInlineResult(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnCallbackQuery(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnCallbackQuery(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1506,12 +1581,13 @@ public static BotActionBuilder OnCallbackQuery(this BotActionCatalogFactory fact /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnEditedMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnEditedMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1530,12 +1606,14 @@ public static BotActionBuilder OnEditedMessage(this BotActionCatalogFactory fact /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnEditedChannelPost(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnEditedChannelPost(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1554,12 +1632,13 @@ public static BotActionBuilder OnEditedChannelPost(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnShippingQuery(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnShippingQuery(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1578,12 +1657,13 @@ public static BotActionBuilder OnShippingQuery(this BotActionCatalogFactory fact /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnPreCheckoutQuery(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnPreCheckoutQuery(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1601,12 +1681,13 @@ public static BotActionBuilder OnPreCheckoutQuery(this BotActionCatalogFactory f /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnPollUpdate(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnPollUpdate(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1624,12 +1705,13 @@ public static BotActionBuilder OnPollUpdate(this BotActionCatalogFactory factory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnPollAnswer(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnPollAnswer(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1648,12 +1730,13 @@ public static BotActionBuilder OnPollAnswer(this BotActionCatalogFactory factory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnMyChatMember(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnMyChatMember(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1671,12 +1754,13 @@ public static BotActionBuilder OnMyChatMember(this BotActionCatalogFactory facto /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnChatMember(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnChatMember(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1695,12 +1779,13 @@ public static BotActionBuilder OnChatMember(this BotActionCatalogFactory factory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnChatJoinRequest(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnChatJoinRequest(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1719,12 +1804,13 @@ public static BotActionBuilder OnChatJoinRequest(this BotActionCatalogFactory fa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnMessageReaction(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnMessageReaction(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1743,12 +1829,14 @@ public static BotActionBuilder OnMessageReaction(this BotActionCatalogFactory fa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnMessageReactionCount(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnMessageReactionCount(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1766,12 +1854,13 @@ public static BotActionBuilder OnMessageReactionCount(this BotActionCatalogFacto /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnChatBoost(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnChatBoost(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1790,12 +1879,13 @@ public static BotActionBuilder OnChatBoost(this BotActionCatalogFactory factory, /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnRemovedChatBoost(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnRemovedChatBoost(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1814,12 +1904,14 @@ public static BotActionBuilder OnRemovedChatBoost(this BotActionCatalogFactory f /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnBusinessConnection(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnBusinessConnection(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1838,12 +1930,13 @@ public static BotActionBuilder OnBusinessConnection(this BotActionCatalogFactory /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnBusinessMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnBusinessMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1862,12 +1955,14 @@ public static BotActionBuilder OnBusinessMessage(this BotActionCatalogFactory fa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnEditedBusinessMessage(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnEditedBusinessMessage(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1886,12 +1981,14 @@ public static BotActionBuilder OnEditedBusinessMessage(this BotActionCatalogFact /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnDeletedBusinessMessages(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnDeletedBusinessMessages(this BotActionCatalogFactory factory, Delegate condition, + Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); @@ -1910,12 +2007,13 @@ public static BotActionBuilder OnDeletedBusinessMessages(this BotActionCatalogFa /// Must return or where TResult is /// /// - /// A delegate representing the action to take when the condition is met. + /// A delegate representing the action to take when the condition is met. Optional if it will be specified later using + /// . /// /// /// A configured instance of that allows further customization of the bot action. /// - public static BotActionBuilder OnUnknownUpdate(this BotActionCatalogFactory factory, Delegate condition, Delegate handler) + public static BotActionBuilder OnUnknownUpdate(this BotActionCatalogFactory factory, Delegate condition, Delegate? handler = default) { var actionBuilder = factory.OnUpdate(condition, handler); diff --git a/src/Navigator/Configuration/Options/NavigatorOptionsCollectionExtensions.cs b/src/Navigator/Configuration/Options/NavigatorOptionsCollectionExtensions.cs index 3999c91..5c87230 100644 --- a/src/Navigator/Configuration/Options/NavigatorOptionsCollectionExtensions.cs +++ b/src/Navigator/Configuration/Options/NavigatorOptionsCollectionExtensions.cs @@ -118,27 +118,27 @@ public static void SetTelegramToken(this NavigatorOptions navigatorOptions, stri #endregion - #region TypingNotification + #region ChatActionNotification - private const string TypingNotificationKey = "_navigator.options.typing_notification"; + private const string ChatActionNotificationKey = "_navigator.options.chataction_notification"; /// - /// Enables the sending of + /// Enables the sending of . /// /// - public static void EnableTypingNotification(this NavigatorOptions navigatorOptions) + public static void EnableChatActionNotification(this NavigatorOptions navigatorOptions) { - navigatorOptions.TryRegisterOption(TypingNotificationKey, true); + navigatorOptions.TryRegisterOption(ChatActionNotificationKey, true); } /// - /// Returns true if the sending of is enabled. + /// Returns true if the sending of is enabled. /// /// /// - public static bool TypingNotificationIsEnabled(this INavigatorOptions navigatorOptions) + public static bool ChatActionNotificationIsEnabled(this INavigatorOptions navigatorOptions) { - return navigatorOptions.RetrieveOption(TypingNotificationKey); + return navigatorOptions.RetrieveOption(ChatActionNotificationKey); } #endregion diff --git a/src/Navigator/Navigator.csproj b/src/Navigator/Navigator.csproj index ace5dc9..8a5ec9c 100644 --- a/src/Navigator/Navigator.csproj +++ b/src/Navigator/Navigator.csproj @@ -27,7 +27,7 @@ - + diff --git a/src/Navigator/Strategy/NavigatorStrategy.cs b/src/Navigator/Strategy/NavigatorStrategy.cs index d6f67c3..8e23658 100644 --- a/src/Navigator/Strategy/NavigatorStrategy.cs +++ b/src/Navigator/Strategy/NavigatorStrategy.cs @@ -26,6 +26,7 @@ public class NavigatorStrategy : INavigatorStrategy private readonly IMemoryCache _cache; private readonly BotActionCatalog _catalog; private readonly IUpdateClassifier _classifier; + private readonly INavigatorClient _client; private readonly ILogger _logger; private readonly INavigatorOptions _options; private readonly IServiceProvider _serviceProvider; @@ -36,11 +37,12 @@ public class NavigatorStrategy : INavigatorStrategy /// The instance. /// The instance. /// The instance. + /// The instance. /// The instance. /// The instance. /// The instance. public NavigatorStrategy(IMemoryCache cache, BotActionCatalogFactory catalogFactory, IUpdateClassifier classifier, - INavigatorOptions options, IServiceProvider serviceProvider, ILogger logger) + INavigatorClient client, INavigatorOptions options, IServiceProvider serviceProvider, ILogger logger) { _cache = cache; _catalog = catalogFactory.Retrieve(); @@ -48,6 +50,7 @@ public NavigatorStrategy(IMemoryCache cache, BotActionCatalogFactory catalogFact _options = options; _serviceProvider = serviceProvider; _logger = logger; + _client = client; } /// @@ -60,11 +63,13 @@ public async Task Invoke(Update update) { _logger.LogInformation("Processing update {UpdateId}", update.Id); - if (_options.TypingNotificationIsEnabled() && update.GetChatOrDefault() is { } chat) + var chat = update.GetChatOrDefault(); + + if (_options.ChatActionNotificationIsEnabled() && chat is not null) { _logger.LogInformation("Sending typing notification to chat {ChatId}", chat.Id); - await _serviceProvider.GetRequiredService().SendChatActionAsync(chat, ChatAction.Typing); + await _client.SendChatActionAsync(chat, ChatAction.Typing); } var updateCategory = await _classifier.Process(update); @@ -76,11 +81,24 @@ public async Task Invoke(Update update) _logger.LogInformation("Found {RelevantActionsCount} relevant actions for {UpdateId}", relevantActions.Count(), update.Id); + _logger.LogDebug("Actions relevant for update {UpdateId}: {ActionsFound}", update.Id, + string.Join(", ", relevantActions.Select(action => action.Information.Name))); + relevantActions = relevantActions.Where(action => IsNotInCooldown(action, update)); + _logger.LogDebug("Actions relevant for update {UpdateId} which are not in cooldown: {ActionsFound}", update.Id, + string.Join(", ", relevantActions.Select(action => action.Information.Name))); + await foreach (var action in FilterActionsThatCanHandleUpdate(relevantActions, update)) { - _logger.LogInformation("Executing action {ActionId}", action.Id); + _logger.LogInformation("Executing action {ActionName}", action.Information.Name); + + if (_options.ChatActionNotificationIsEnabled() && chat is not null && action.Information.ChatAction is not null) + { + _logger.LogDebug("Sending {ChatAction} notification to chat {ChatId}", action.Information.ChatAction.Value, chat.Id); + + await _client.SendChatActionAsync(chat, action.Information.ChatAction.Value); + } await ExecuteAction(action, update); } @@ -94,7 +112,11 @@ public async Task Invoke(Update update) /// true if the is in cooldown; otherwise, false. private bool IsNotInCooldown(BotAction botAction, Update update) { - return !_cache.TryGetValue(GenerateCacheKey(botAction, update), out _); + var isNotInCooldown = !_cache.TryGetValue(GenerateCacheKey(botAction, update), out _); + + if (isNotInCooldown is false) _logger.LogDebug("Discarding action {ActionName} because is in cooldown", botAction.Information.Name); + + return isNotInCooldown; } /// @@ -128,11 +150,21 @@ private async IAsyncEnumerable FilterActionsThatCanHandleUpdate(IEnum arguments[i] = await GetArgument(inputType, update, action); } - if (!await action.ExecuteCondition(arguments)) continue; + if (!await action.ExecuteCondition(arguments)) + { + _logger.LogDebug("Discarding action {ActionName} because condition is not met", action.Information.Name); + + continue; + } yield return action; - if (_options.MultipleActionsUsageIsEnabled() is false) break; + if (_options.MultipleActionsUsageIsEnabled() is false) + { + _logger.LogDebug("Discarding other actions because multiple actions usage is disabled"); + + break; + } } } @@ -156,7 +188,13 @@ private async Task ExecuteAction(BotAction action, Update update) await action.ExecuteHandler(arguments); - if (action.Information.Cooldown.HasValue) _cache.Set(GenerateCacheKey(action, update), true, action.Information.Cooldown.Value); + if (action.Information.Cooldown.HasValue) + { + _logger.LogDebug("Setting action {ActionName} to cooldown for {Cooldown} minutes", action.Information.Name, + action.Information.Cooldown.Value.TotalMinutes); + + _cache.Set(GenerateCacheKey(action, update), true, action.Information.Cooldown.Value); + } } private async Task GetArgument(Type inputType, Update update, BotAction action) diff --git a/src/Sample/Program.cs b/src/Sample/Program.cs index f779de1..223ecb2 100644 --- a/src/Sample/Program.cs +++ b/src/Sample/Program.cs @@ -21,7 +21,7 @@ { options.SetWebHookBaseUrl(builder.Configuration["BASE_WEBHOOK_URL"]!); options.SetTelegramToken(builder.Configuration["TELEGRAM_TOKEN"]!); - options.EnableTypingNotification(); + options.EnableChatActionNotification(); options.EnableMultipleActionsUsage(); }); @@ -40,12 +40,11 @@ // This action will be triggered for every message sent to the chat. Additionally in this code example, this action will be triggered // only if NavigatorOptions.MultipleActionsUSageIsEnabled is set to true. bot.OnMessage((Update _) => true, async (INavigatorClient client, Chat chat, Message message) => - { - var text = $"message received: {message.MessageId}"; +{ + var text = $"message received: {message.MessageId}"; - await client.SendTextMessageAsync(chat, text); - }) - .WithCooldown(TimeSpan.FromSeconds(30)); + await client.SendTextMessageAsync(chat, text); +}).WithCooldown(TimeSpan.FromSeconds(30)); app.MapNavigator();