diff --git a/src/Navigator.Extensions.Store/Context/NavigatorDbContext.cs b/src/Navigator.Extensions.Store/Context/NavigatorDbContext.cs index de4e291..9c0c99d 100644 --- a/src/Navigator.Extensions.Store/Context/NavigatorDbContext.cs +++ b/src/Navigator.Extensions.Store/Context/NavigatorDbContext.cs @@ -20,9 +20,24 @@ public NavigatorDbContext(DbContextOptions options) : base(o { } + /// + /// Bots. + /// public required DbSet Bots { get; set; } + + /// + /// Users. + /// public required DbSet Users { get; set; } + + /// + /// Chats. + /// public required DbSet Chats { get; set; } + + /// + /// Conversations. + /// public required DbSet Conversations { get; set; } /// diff --git a/src/Navigator.Extensions.Store/Entities/Chat.cs b/src/Navigator.Extensions.Store/Entities/Chat.cs index 8c1f9d8..5148924 100644 --- a/src/Navigator.Extensions.Store/Entities/Chat.cs +++ b/src/Navigator.Extensions.Store/Entities/Chat.cs @@ -1,3 +1,5 @@ +using Navigator.Entities; + namespace Navigator.Extensions.Store.Entities; /// @@ -32,10 +34,30 @@ public Chat(Navigator.Entities.Chat chat) } + /// + /// Id of the chat. + /// public long Id { get; set; } + /// + /// Title of the chat. + /// + /// Optional. + /// + /// public string? Title { get; set; } + + /// + /// Type of the chat, can be any of . + /// public Navigator.Entities.Chat.ChatType Type { get; set; } + + /// + /// If the supergroup chat is a forum (has topics enabled). + /// + /// Optional. + /// + /// public bool? IsForum { get; set; } /// diff --git a/src/Navigator.Extensions.Store/Entities/Conversation.cs b/src/Navigator.Extensions.Store/Entities/Conversation.cs index 1879586..7045f6c 100644 --- a/src/Navigator.Extensions.Store/Entities/Conversation.cs +++ b/src/Navigator.Extensions.Store/Entities/Conversation.cs @@ -1,5 +1,8 @@ namespace Navigator.Extensions.Store.Entities; +/// +/// Conversation. +/// public class Conversation { /// @@ -21,6 +24,9 @@ public Conversation(User user, Chat chat) FirstInteractionAt = DateTime.UtcNow; } + /// + /// Id of the user. + /// public long UserId { get; set; } /// @@ -28,6 +34,9 @@ public Conversation(User user, Chat chat) /// public User User { get; set; } = null!; + /// + /// Id of the chat. + /// public long ChatId { get; set; } /// diff --git a/src/Navigator.Extensions.Store/NavigatorContextExtensions.cs b/src/Navigator.Extensions.Store/NavigatorContextExtensions.cs index 5f50a73..dad3d45 100644 --- a/src/Navigator.Extensions.Store/NavigatorContextExtensions.cs +++ b/src/Navigator.Extensions.Store/NavigatorContextExtensions.cs @@ -1,10 +1,11 @@ using Navigator.Context; -using Navigator.Extensions.Bundled.OriginalEvent; using Navigator.Extensions.Store.Context; -using Telegram.Bot.Types; namespace Navigator.Extensions.Store; +/// +/// Extensions for . +/// public static class NavigatorContextExtensions { #region NavigatorStore diff --git a/src/Navigator.Extensions.Store/NavigatorStoreException.cs b/src/Navigator.Extensions.Store/NavigatorStoreException.cs index f180adc..c9af92f 100644 --- a/src/Navigator.Extensions.Store/NavigatorStoreException.cs +++ b/src/Navigator.Extensions.Store/NavigatorStoreException.cs @@ -2,20 +2,27 @@ namespace Navigator.Extensions.Store; +/// +/// Navigator Store exception. +/// public class NavigatorStoreException : NavigatorException { + /// public NavigatorStoreException() { } + /// protected NavigatorStoreException(SerializationInfo info, StreamingContext context) : base(info, context) { } + /// public NavigatorStoreException(string? message) : base(message) { } + /// public NavigatorStoreException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/src/Navigator/Actions/ActionHandler.cs b/src/Navigator/Actions/ActionHandler.cs index 760b06f..fd15aa1 100644 --- a/src/Navigator/Actions/ActionHandler.cs +++ b/src/Navigator/Actions/ActionHandler.cs @@ -4,24 +4,49 @@ namespace Navigator.Actions; +/// +/// Implement to handle an action. +/// +/// public abstract class ActionHandler : IRequestHandler where TAction : IAction { + /// + /// Context for the action. + /// public readonly INavigatorContext Context; + /// + /// Default constructor. + /// + /// protected ActionHandler(INavigatorContextAccessor navigatorContextAccessor) { Context = navigatorContextAccessor.NavigatorContext; } + /// + /// Handles the action. + /// + /// + /// + /// public abstract Task Handle(TAction action, CancellationToken cancellationToken); - public static Status Success() + /// + /// Called when the action was handled successfully. + /// + /// + protected static Status Success() { - return new(true); + return new Status(true); } - public static Status Error() + /// + /// Called when the action was not handled successfully. + /// + /// + protected static Status Error() { - return new(false); + return new Status(false); } } \ No newline at end of file diff --git a/src/Navigator/Actions/ActionHandlerExtensions.cs b/src/Navigator/Actions/ActionHandlerExtensions.cs deleted file mode 100644 index 7e4403c..0000000 --- a/src/Navigator/Actions/ActionHandlerExtensions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Navigator.Actions; - -public class ActionHandlerExtensions -{ - -} \ No newline at end of file diff --git a/src/Navigator/Actions/Attributes/ActionPriorityAttribute.cs b/src/Navigator/Actions/Attributes/ActionPriorityAttribute.cs index fb2ee3b..4254103 100644 --- a/src/Navigator/Actions/Attributes/ActionPriorityAttribute.cs +++ b/src/Navigator/Actions/Attributes/ActionPriorityAttribute.cs @@ -6,8 +6,15 @@ namespace Navigator.Actions.Attributes; [System.AttributeUsage(System.AttributeTargets.Class)] public class ActionPriorityAttribute : System.Attribute { + /// + /// Priority. + /// public readonly ushort Priority; + /// + /// Sets the action priority. + /// + /// public ActionPriorityAttribute(ushort priority) { Priority = priority; diff --git a/src/Navigator/Actions/Attributes/ActionTypeAttribute.cs b/src/Navigator/Actions/Attributes/ActionTypeAttribute.cs index 3383e7e..eced23b 100644 --- a/src/Navigator/Actions/Attributes/ActionTypeAttribute.cs +++ b/src/Navigator/Actions/Attributes/ActionTypeAttribute.cs @@ -1,10 +1,20 @@ namespace Navigator.Actions.Attributes; +/// +/// Attribute for setting the action type. +/// [System.AttributeUsage(System.AttributeTargets.Class)] public class ActionTypeAttribute : System.Attribute { - public string ActionType; + /// + /// Action type. + /// + public readonly string ActionType; + /// + /// Sets the action type. + /// + /// public ActionTypeAttribute(string action) { ActionType = action; diff --git a/src/Navigator/Actions/BaseAction.cs b/src/Navigator/Actions/BaseAction.cs index 81310aa..c47bd7b 100644 --- a/src/Navigator/Actions/BaseAction.cs +++ b/src/Navigator/Actions/BaseAction.cs @@ -17,6 +17,9 @@ public abstract class BaseAction : IAction /// protected INavigatorContext Context => _navigatorContextAccessor.NavigatorContext; + /// + /// Priority of the request. + /// public virtual ushort Priority { get; protected set; } = Actions.Priority.Default; /// diff --git a/src/Navigator/Actions/IActionLauncher.cs b/src/Navigator/Actions/IActionLauncher.cs index 080895b..ac122b5 100644 --- a/src/Navigator/Actions/IActionLauncher.cs +++ b/src/Navigator/Actions/IActionLauncher.cs @@ -1,6 +1,13 @@ namespace Navigator.Actions; +/// +/// Action launcher interface. +/// public interface IActionLauncher { + /// + /// Launches one or more actions. + /// + /// Task Launch(); } \ No newline at end of file diff --git a/src/Navigator/Actions/IActionMiddleware.cs b/src/Navigator/Actions/IActionMiddleware.cs index 6730605..fec8344 100644 --- a/src/Navigator/Actions/IActionMiddleware.cs +++ b/src/Navigator/Actions/IActionMiddleware.cs @@ -3,7 +3,7 @@ namespace Navigator.Actions; /// -/// TODO +/// Interface to implement middleware for actions. /// /// /// diff --git a/src/Navigator/Actions/NavigatorOptionsExtensions.cs b/src/Navigator/Actions/NavigatorOptionsExtensions.cs index d4c5d67..859ef05 100644 --- a/src/Navigator/Actions/NavigatorOptionsExtensions.cs +++ b/src/Navigator/Actions/NavigatorOptionsExtensions.cs @@ -4,6 +4,9 @@ namespace Navigator.Actions; +/// +/// Extensions for . +/// public static class NavigatorOptionsExtensions { #region NavigatorActionTypeCollection diff --git a/src/Navigator/Actions/Priority.cs b/src/Navigator/Actions/Priority.cs index 7ddfa02..0ab6ded 100644 --- a/src/Navigator/Actions/Priority.cs +++ b/src/Navigator/Actions/Priority.cs @@ -1,8 +1,22 @@ namespace Navigator.Actions; +/// +/// Priority presets. +/// public static class Priority { + /// + /// Low priority. + /// public const ushort Low = 15000; + + /// + /// Default priority + /// public const ushort Default = 10000; + + /// + /// High priority. + /// public const ushort High = 5000; } \ No newline at end of file diff --git a/src/Navigator/Actions/Status.cs b/src/Navigator/Actions/Status.cs index 1bcd3d5..51d9342 100644 --- a/src/Navigator/Actions/Status.cs +++ b/src/Navigator/Actions/Status.cs @@ -1,12 +1,26 @@ namespace Navigator.Actions; -public struct Status +/// +/// Represents the outcome of an action. +/// +public readonly struct Status { private readonly bool _isSuccess; + /// + /// Is success. + /// public bool IsSuccess => _isSuccess; + + /// + /// Is error. + /// public bool IsError => !_isSuccess; + /// + /// Default constructor. + /// + /// public Status(bool isSuccess) { _isSuccess = isSuccess; diff --git a/src/Navigator/Bundled/Actions/ActionHandlerExtensions.cs b/src/Navigator/Bundled/Actions/ActionHandlerExtensions.cs deleted file mode 100644 index ee66a9f..0000000 --- a/src/Navigator/Bundled/Actions/ActionHandlerExtensions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// using Navigator.Old; -// using Telegram.Bot.Types; -// -// namespace Navigator.Actions.Telegram; -// -// public static class ActionHandlerExtensions -// { -// public static NavigatorTelegramClient GetTelegramClient(this ActionHandler actionHandler) where T : IAction -// { -// return actionHandler.Context.Provider.GetTelegramClient(); -// } -// -// public static Chat GetTelegramChat(this ActionHandler actionHandler) where T : IAction -// { -// return actionHandler.Context.GetTelegramChat(); -// } -// } \ No newline at end of file diff --git a/src/Navigator/Bundled/Actions/Bundled/CommandAction.cs b/src/Navigator/Bundled/Actions/CommandAction.cs similarity index 94% rename from src/Navigator/Bundled/Actions/Bundled/CommandAction.cs rename to src/Navigator/Bundled/Actions/CommandAction.cs index 1b92978..6cf159d 100644 --- a/src/Navigator/Bundled/Actions/Bundled/CommandAction.cs +++ b/src/Navigator/Bundled/Actions/CommandAction.cs @@ -3,7 +3,7 @@ using Navigator.Context.Accessor; using Navigator.Telegram; -namespace Navigator.Bundled.Actions.Bundled; +namespace Navigator.Bundled.Actions; /// /// Command based action. diff --git a/src/Navigator/Bundled/Actions/Messages/MessageAction.cs b/src/Navigator/Bundled/Actions/Messages/MessageAction.cs index c7db504..49b4d54 100644 --- a/src/Navigator/Bundled/Actions/Messages/MessageAction.cs +++ b/src/Navigator/Bundled/Actions/Messages/MessageAction.cs @@ -1,7 +1,7 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Messages; @@ -25,7 +25,7 @@ public abstract class MessageAction : BaseAction /// /// Timestamp of the message creation. /// - public readonly DateTime Timestamp; + public new readonly DateTime Timestamp; /// /// Determines if this message is a reply to another message. @@ -40,7 +40,7 @@ public abstract class MessageAction : BaseAction /// protected MessageAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = navigatorContextAccessor.NavigatorContext.GetOriginalEvent(); + var update = navigatorContextAccessor.NavigatorContext.GetUpdate(); Message = update.Message!; ChatId = Context.Conversation.Chat!.Id; diff --git a/src/Navigator/Bundled/Actions/Messages/PhotoAction.cs b/src/Navigator/Bundled/Actions/Messages/PhotoAction.cs index f538e47..a686875 100644 --- a/src/Navigator/Bundled/Actions/Messages/PhotoAction.cs +++ b/src/Navigator/Bundled/Actions/Messages/PhotoAction.cs @@ -1,5 +1,4 @@ using Navigator.Actions.Attributes; -using Navigator.Bundled.Actions.Bundled; using Navigator.Context.Accessor; using Navigator.Telegram; using Telegram.Bot.Types; diff --git a/src/Navigator/Bundled/Actions/Messages/TextAction.cs b/src/Navigator/Bundled/Actions/Messages/TextAction.cs index a18378d..0e273cf 100644 --- a/src/Navigator/Bundled/Actions/Messages/TextAction.cs +++ b/src/Navigator/Bundled/Actions/Messages/TextAction.cs @@ -1,5 +1,4 @@ using Navigator.Actions.Attributes; -using Navigator.Bundled.Actions.Bundled; using Navigator.Context.Accessor; using Navigator.Telegram; diff --git a/src/Navigator/Bundled/Actions/UnknownAction.cs b/src/Navigator/Bundled/Actions/UnknownAction.cs index 71e75ec..d3b9d74 100644 --- a/src/Navigator/Bundled/Actions/UnknownAction.cs +++ b/src/Navigator/Bundled/Actions/UnknownAction.cs @@ -4,6 +4,10 @@ namespace Navigator.Bundled.Actions; +/// +/// Represents an unknown action. +/// If you are seeing this, something probably went wrong. +/// [ActionType(nameof(UnknownAction))] public abstract class UnknownAction : BaseAction { diff --git a/src/Navigator/Bundled/Actions/Updates/CallbackQueryAction.cs b/src/Navigator/Bundled/Actions/Updates/CallbackQueryAction.cs index cea8d4c..a68e9a7 100644 --- a/src/Navigator/Bundled/Actions/Updates/CallbackQueryAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/CallbackQueryAction.cs @@ -1,7 +1,7 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; @@ -35,7 +35,7 @@ public abstract class CallbackQueryAction : BaseAction /// protected CallbackQueryAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); CallbackQuery = update.CallbackQuery!; OriginalMessage = CallbackQuery.Message; diff --git a/src/Navigator/Bundled/Actions/Updates/ChannelCreatedAction.cs b/src/Navigator/Bundled/Actions/Updates/ChannelCreatedAction.cs index 4c84d88..b15c239 100644 --- a/src/Navigator/Bundled/Actions/Updates/ChannelCreatedAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/ChannelCreatedAction.cs @@ -5,7 +5,7 @@ namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered by a Channel being created. /// [ActionType(nameof(ChannelCreatedAction))] public abstract class ChannelCreatedAction : BaseAction diff --git a/src/Navigator/Bundled/Actions/Updates/ChannelPostAction.cs b/src/Navigator/Bundled/Actions/Updates/ChannelPostAction.cs index 31dea56..917f251 100644 --- a/src/Navigator/Bundled/Actions/Updates/ChannelPostAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/ChannelPostAction.cs @@ -1,13 +1,13 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered by a post being sent to a channel. /// [ActionType(nameof(ChannelPostAction))] public abstract class ChannelPostAction : BaseAction @@ -20,7 +20,7 @@ public abstract class ChannelPostAction : BaseAction /// protected ChannelPostAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); ChannelPost = update.ChannelPost!; } diff --git a/src/Navigator/Bundled/Actions/Updates/ChatJoinRequestAction.cs b/src/Navigator/Bundled/Actions/Updates/ChatJoinRequestAction.cs index 65ac49e..565bd4b 100644 --- a/src/Navigator/Bundled/Actions/Updates/ChatJoinRequestAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/ChatJoinRequestAction.cs @@ -1,13 +1,13 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered by a request to join a channel. /// [ActionType(nameof(ChatJoinRequestAction))] public abstract class ChatJoinRequestAction : BaseAction @@ -20,7 +20,7 @@ public abstract class ChatJoinRequestAction : BaseAction /// protected ChatJoinRequestAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); Request = update.ChatJoinRequest!; } diff --git a/src/Navigator/Bundled/Actions/Updates/ChatMemberAction.cs b/src/Navigator/Bundled/Actions/Updates/ChatMemberAction.cs index a1ba9b2..c5142f4 100644 --- a/src/Navigator/Bundled/Actions/Updates/ChatMemberAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/ChatMemberAction.cs @@ -1,13 +1,13 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered when a chat member has been updated. /// [ActionType(nameof(ChatMemberAction))] public abstract class ChatMemberAction : BaseAction @@ -20,7 +20,7 @@ public abstract class ChatMemberAction : BaseAction /// protected ChatMemberAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); ChatMemberUpdated = update.ChatMember!; } diff --git a/src/Navigator/Bundled/Actions/Updates/ChosenInlineResultAction.cs b/src/Navigator/Bundled/Actions/Updates/ChosenInlineResultAction.cs index ad8b059..63e5672 100644 --- a/src/Navigator/Bundled/Actions/Updates/ChosenInlineResultAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/ChosenInlineResultAction.cs @@ -1,7 +1,7 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; @@ -30,7 +30,7 @@ public abstract class ChosenInlineResultAction : BaseAction /// protected ChosenInlineResultAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); ChosenInlineResult = update.ChosenInlineResult!; ResultId = update.ChosenInlineResult!.ResultId; diff --git a/src/Navigator/Bundled/Actions/Updates/DocumentAction.cs b/src/Navigator/Bundled/Actions/Updates/DocumentAction.cs index 0e6ed3f..98db447 100644 --- a/src/Navigator/Bundled/Actions/Updates/DocumentAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/DocumentAction.cs @@ -1,18 +1,27 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; +using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered by a document being sent. /// [ActionType(nameof(DocumentAction))] public abstract class DocumentAction : BaseAction { + /// + /// Document. + /// + public Document Document { get; set; } + /// public DocumentAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - //TODO + var update = Context.GetUpdate(); + Document = update.Message!.Document!; } + } \ No newline at end of file diff --git a/src/Navigator/Bundled/Actions/Updates/EditedChannelPostAction.cs b/src/Navigator/Bundled/Actions/Updates/EditedChannelPostAction.cs index 8572075..d6041b8 100644 --- a/src/Navigator/Bundled/Actions/Updates/EditedChannelPostAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/EditedChannelPostAction.cs @@ -1,21 +1,26 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; +using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered by a post sent to a channel. /// [ActionType(nameof(EditedChannelPostAction))] public abstract class EditedChannelPostAction : BaseAction { + /// + /// Edited channel post. + /// + public Message ChannelPost { get; set; } + /// protected EditedChannelPostAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - //TODO + ChannelPost = Context.GetUpdate().EditedChannelPost!; } - - } \ No newline at end of file diff --git a/src/Navigator/Bundled/Actions/Updates/EditedMessageAction.cs b/src/Navigator/Bundled/Actions/Updates/EditedMessageAction.cs index 56e6bf3..e03ab19 100644 --- a/src/Navigator/Bundled/Actions/Updates/EditedMessageAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/EditedMessageAction.cs @@ -1,31 +1,34 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered when a message is edited. +/// +/// Caution. Does not always works. +/// /// [ActionType(nameof(EditedMessageAction))] public abstract class EditedMessageAction : BaseAction { /// - /// TODO + /// Original . /// public Message OriginalMessage { get; protected set; } /// - /// TODO + /// Edited . /// public Message EditedMessage { get; protected set; } /// protected EditedMessageAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); OriginalMessage = update.Message!; EditedMessage = update.EditedMessage!; diff --git a/src/Navigator/Bundled/Actions/Updates/InlineQueryAction.cs b/src/Navigator/Bundled/Actions/Updates/InlineQueryAction.cs index 0846128..e062e2f 100644 --- a/src/Navigator/Bundled/Actions/Updates/InlineQueryAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/InlineQueryAction.cs @@ -1,7 +1,7 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; @@ -30,7 +30,7 @@ public abstract class InlineQueryAction : BaseAction /// protected InlineQueryAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); InlineQuery = update.InlineQuery!; Query = update.InlineQuery!.Query; diff --git a/src/Navigator/Bundled/Actions/Updates/MyChatMemberAction.cs b/src/Navigator/Bundled/Actions/Updates/MyChatMemberAction.cs index 6051592..62af103 100644 --- a/src/Navigator/Bundled/Actions/Updates/MyChatMemberAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/MyChatMemberAction.cs @@ -1,13 +1,14 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered when the bot’s chat member status was updated in a chat. +/// For private chats, this update is received only when the bot is blocked or unblocked by the user. /// [ActionType(nameof(MyChatMemberAction))] public abstract class MyChatMemberAction : BaseAction @@ -15,13 +16,13 @@ public abstract class MyChatMemberAction : BaseAction /// /// Chat member updated. /// - public ChatMemberUpdated ChatMemberUpdated { get; set; } + public ChatMemberUpdated MyChatMember { get; set; } /// protected MyChatMemberAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); - ChatMemberUpdated = update.MyChatMember!; + MyChatMember = update.MyChatMember!; } } \ No newline at end of file diff --git a/src/Navigator/Bundled/Actions/Updates/PollAnswerAction.cs b/src/Navigator/Bundled/Actions/Updates/PollAnswerAction.cs index 417597c..4ef0368 100644 --- a/src/Navigator/Bundled/Actions/Updates/PollAnswerAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/PollAnswerAction.cs @@ -1,11 +1,14 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; +/// +/// Action triggered by a poll being answered. +/// [ActionType(nameof(PollAnswerAction))] public abstract class PollAnswerAction : BaseAction { @@ -17,7 +20,7 @@ public abstract class PollAnswerAction : BaseAction /// protected PollAnswerAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); Answer = update.PollAnswer!; } diff --git a/src/Navigator/Bundled/Actions/Updates/PollUpdateAction.cs b/src/Navigator/Bundled/Actions/Updates/PollUpdateAction.cs index 282a2c8..c1bf2ea 100644 --- a/src/Navigator/Bundled/Actions/Updates/PollUpdateAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/PollUpdateAction.cs @@ -1,13 +1,13 @@ using Navigator.Actions; using Navigator.Actions.Attributes; +using Navigator.Bundled.Extensions.Update; using Navigator.Context.Accessor; -using Navigator.Extensions.Bundled; using Telegram.Bot.Types; namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered by a being updated. /// [ActionType(nameof(PollUpdateAction))] public abstract class PollUpdateAction : BaseAction @@ -20,7 +20,7 @@ public abstract class PollUpdateAction : BaseAction /// protected PollUpdateAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - var update = Context.GetOriginalEvent(); + var update = Context.GetUpdate(); Poll = update.Poll!; } diff --git a/src/Navigator/Bundled/Actions/Updates/PreCheckoutQueryAction.cs b/src/Navigator/Bundled/Actions/Updates/PreCheckoutQueryAction.cs index 56be231..e263893 100644 --- a/src/Navigator/Bundled/Actions/Updates/PreCheckoutQueryAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/PreCheckoutQueryAction.cs @@ -5,7 +5,7 @@ namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered by a pre-checkout query being sent. /// [ActionType(nameof(PreCheckoutQueryAction))] public abstract class PreCheckoutQueryAction : BaseAction @@ -13,7 +13,6 @@ public abstract class PreCheckoutQueryAction : BaseAction /// protected PreCheckoutQueryAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - //TODO } } \ No newline at end of file diff --git a/src/Navigator/Bundled/Actions/Updates/ShippingQueryAction.cs b/src/Navigator/Bundled/Actions/Updates/ShippingQueryAction.cs index e8bfa10..321e380 100644 --- a/src/Navigator/Bundled/Actions/Updates/ShippingQueryAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/ShippingQueryAction.cs @@ -5,7 +5,7 @@ namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// action triggered by a shipping query being sent. /// [ActionType(nameof(ShippingQueryAction))] public abstract class ShippingQueryAction : BaseAction @@ -13,7 +13,6 @@ public abstract class ShippingQueryAction : BaseAction /// protected ShippingQueryAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - //TODO } } \ No newline at end of file diff --git a/src/Navigator/Bundled/Actions/Updates/SupergroupCreatedAction.cs b/src/Navigator/Bundled/Actions/Updates/SupergroupCreatedAction.cs index f5a8eaa..89e6488 100644 --- a/src/Navigator/Bundled/Actions/Updates/SupergroupCreatedAction.cs +++ b/src/Navigator/Bundled/Actions/Updates/SupergroupCreatedAction.cs @@ -5,7 +5,7 @@ namespace Navigator.Bundled.Actions.Updates; /// -/// TODO +/// Action triggered by a supergroup being created. /// [ActionType(nameof(SupergroupCreatedAction))] public abstract class SupergroupCreatedAction : BaseAction @@ -13,7 +13,7 @@ public abstract class SupergroupCreatedAction : BaseAction /// protected SupergroupCreatedAction(INavigatorContextAccessor navigatorContextAccessor) : base(navigatorContextAccessor) { - //TODO + } } \ No newline at end of file diff --git a/src/Navigator/Bundled/Extensions/ActionType/NavigatorContextBuilderOptionsExtensions.cs b/src/Navigator/Bundled/Extensions/ActionType/NavigatorContextBuilderOptionsExtensions.cs new file mode 100644 index 0000000..ac8e18f --- /dev/null +++ b/src/Navigator/Bundled/Extensions/ActionType/NavigatorContextBuilderOptionsExtensions.cs @@ -0,0 +1,24 @@ +using Navigator.Context.Builder.Options; +using Telegram.Bot.Types; + +namespace Navigator.Bundled.Extensions.ActionType; + +internal static class NavigatorContextBuilderOptionsExtensions +{ + #region ActionType + + private const string ActionTypeKey = "_navigator.context.options.action_type"; + + public static void SetActionType(this INavigatorContextBuilderOptions contextBuilderOptions, string actionType) + { + contextBuilderOptions.TryRegisterOption(ActionTypeKey, actionType); + + } + + public static string? GetActionType(this INavigatorContextBuilderOptions contextBuilderOptions) + { + return contextBuilderOptions.RetrieveOption(ActionTypeKey); + } + + #endregion +} \ No newline at end of file diff --git a/src/Navigator/Bundled/Extensions/Update/NavigatorContextBuilderOptionsExtensions.cs b/src/Navigator/Bundled/Extensions/Update/NavigatorContextBuilderOptionsExtensions.cs new file mode 100644 index 0000000..0d989ea --- /dev/null +++ b/src/Navigator/Bundled/Extensions/Update/NavigatorContextBuilderOptionsExtensions.cs @@ -0,0 +1,19 @@ +using Navigator.Context.Builder.Options; + +namespace Navigator.Bundled.Extensions.Update; + +internal static class NavigatorContextBuilderOptionsExtensions +{ + private const string UpdateKey = "_navigator.context.options.update"; + + public static void GetUpdate(this INavigatorContextBuilderOptions contextBuilderOptions, global::Telegram.Bot.Types.Update update) + { + contextBuilderOptions.TryRegisterOption(UpdateKey, update); + + } + + public static global::Telegram.Bot.Types.Update? GetUpdateOrDefault(this INavigatorContextBuilderOptions contextBuilderOptions) + { + return contextBuilderOptions.RetrieveOption(UpdateKey); + } +} \ No newline at end of file diff --git a/src/Navigator/Bundled/Extensions/Update/NavigatorContextExtensions.cs b/src/Navigator/Bundled/Extensions/Update/NavigatorContextExtensions.cs new file mode 100644 index 0000000..753680d --- /dev/null +++ b/src/Navigator/Bundled/Extensions/Update/NavigatorContextExtensions.cs @@ -0,0 +1,40 @@ +using Navigator.Context; +using Telegram.Bot.Types; + +namespace Navigator.Bundled.Extensions.Update; + +/// +/// Bundled extensions to . +/// +public static class NavigatorContextExtensions +{ + /// + /// Returns the . Throws an exception if not found. + /// + /// + /// + /// + public static global::Telegram.Bot.Types.Update GetUpdate(this INavigatorContext navigatorContext) + { + var update = navigatorContext.GetUpdateOrDefault(); + + return update ?? throw new NavigatorException("Update was not found."); + } + + /// + /// Returns the or null if not found. + /// + /// + /// + public static global::Telegram.Bot.Types.Update? GetUpdateOrDefault(this INavigatorContext navigatorContext) + { + var @event = navigatorContext.Extensions.GetValueOrDefault(UpdateNavigatorContextExtension.UpdateKey); + + if (@event is global::Telegram.Bot.Types.Update update) + { + return update; + } + + return default; + } +} \ No newline at end of file diff --git a/src/Navigator/Bundled/Extensions/Update/UpdateNavigatorContextExtension.cs b/src/Navigator/Bundled/Extensions/Update/UpdateNavigatorContextExtension.cs new file mode 100644 index 0000000..c38ff86 --- /dev/null +++ b/src/Navigator/Bundled/Extensions/Update/UpdateNavigatorContextExtension.cs @@ -0,0 +1,17 @@ +using Navigator.Context; +using Navigator.Context.Builder.Options; +using Navigator.Extensions; + +namespace Navigator.Bundled.Extensions.Update; + +internal class UpdateNavigatorContextExtension : INavigatorContextExtension +{ + public const string UpdateKey = "_navigator.extensions.update"; + + public Task Extend(INavigatorContext navigatorContext, INavigatorContextBuilderOptions builderOptions) + { + navigatorContext.Extensions.TryAdd(UpdateKey, builderOptions.GetUpdateOrDefault()); + + return Task.FromResult(navigatorContext); + } +} \ No newline at end of file diff --git a/src/Navigator/Client/INavigatorClient.cs b/src/Navigator/Client/INavigatorClient.cs index 302498e..e1f70f1 100644 --- a/src/Navigator/Client/INavigatorClient.cs +++ b/src/Navigator/Client/INavigatorClient.cs @@ -3,6 +3,9 @@ namespace Navigator.Client; +/// +/// Navigator Client. +/// public interface INavigatorClient : ITelegramBotClient { /// diff --git a/src/Navigator/Client/NavigatorClient.cs b/src/Navigator/Client/NavigatorClient.cs index 219ceb5..0e40063 100644 --- a/src/Navigator/Client/NavigatorClient.cs +++ b/src/Navigator/Client/NavigatorClient.cs @@ -23,8 +23,9 @@ public async Task GetProfile(CancellationToken cancellationToken = default) { var bot = await this.GetMeAsync(cancellationToken); - return new Bot(bot.Id, bot.Username!, bot.FirstName) + return new Bot(bot.Id, bot.FirstName) { + Username = bot.Username!, LastName = bot.LastName, CanJoinGroups = bot.CanJoinGroups, CanReadAllGroupMessages = bot.CanReadAllGroupMessages, diff --git a/src/Navigator/Configuration/EndpointRouteBuilderExtensions.cs b/src/Navigator/Configuration/EndpointRouteBuilderExtensions.cs index d045956..2584718 100644 --- a/src/Navigator/Configuration/EndpointRouteBuilderExtensions.cs +++ b/src/Navigator/Configuration/EndpointRouteBuilderExtensions.cs @@ -8,6 +8,9 @@ namespace Navigator.Configuration; +/// +/// Navigator extensions for . +/// public static class EndpointRouteBuilderExtensions { /// diff --git a/src/Navigator/Configuration/INavigatorOptions.cs b/src/Navigator/Configuration/INavigatorOptions.cs index 8a5ae78..b7f9362 100644 --- a/src/Navigator/Configuration/INavigatorOptions.cs +++ b/src/Navigator/Configuration/INavigatorOptions.cs @@ -5,9 +5,39 @@ namespace Navigator.Configuration; /// public interface INavigatorOptions { + /// + /// Registers an option, fails if the option already exists. + /// + /// + /// + /// bool TryRegisterOption(string key, object option); + + /// + /// Registers an option, overriding any option that may exist. + /// + /// + /// void ForceRegisterOption(string key, object option); + + /// + /// Retrieves an option given a key. + /// + /// + /// + /// TType? RetrieveOption(string key); + + /// + /// Retrieves all options. + /// + /// Dictionary RetrieveAllOptions(); + + /// + /// Imports options in format. + /// + /// + /// void Import(Dictionary options, bool overwrite = false); } \ No newline at end of file diff --git a/src/Navigator/Configuration/NavigatorConfiguration.cs b/src/Navigator/Configuration/NavigatorConfiguration.cs index 67a3c1f..9deb5e8 100644 --- a/src/Navigator/Configuration/NavigatorConfiguration.cs +++ b/src/Navigator/Configuration/NavigatorConfiguration.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Navigator.Configuration.Extensions; -using Navigator.Configuration.Provider; namespace Navigator.Configuration; @@ -10,8 +9,9 @@ namespace Navigator.Configuration; /// public class NavigatorConfiguration { - public NavigatorProviderConfiguration WithProvider { get; internal set; } - + /// + /// Configures an extension for Navigator. + /// public NavigatorExtensionConfiguration WithExtension { get; internal set; } /// @@ -43,12 +43,14 @@ public NavigatorConfiguration(Action options, IServiceCollecti Services = services; services.AddSingleton(Options); - - WithProvider = new NavigatorProviderConfiguration(this); + WithExtension = new NavigatorExtensionConfiguration(this); } + /// + /// Registers the or replaces it if already exists. + /// public void RegisterOrReplaceOptions() { Services.Replace(ServiceDescriptor.Singleton(_ => Options)); diff --git a/src/Navigator/Configuration/NavigatorOptions.cs b/src/Navigator/Configuration/NavigatorOptions.cs index e3629b5..999fb29 100644 --- a/src/Navigator/Configuration/NavigatorOptions.cs +++ b/src/Navigator/Configuration/NavigatorOptions.cs @@ -5,16 +5,21 @@ public class NavigatorOptions : INavigatorOptions { private readonly Dictionary _options; + /// + /// Default constructor. + /// public NavigatorOptions() { _options = new Dictionary(); } + /// public bool TryRegisterOption(string key, object option) { return _options.TryAdd(key, option); } - + + /// public void ForceRegisterOption(string key, object option) { _options.Remove(key); @@ -22,6 +27,7 @@ public void ForceRegisterOption(string key, object option) TryRegisterOption(key, option); } + /// public TType? RetrieveOption(string key) { if (_options.TryGetValue(key, out var option)) @@ -32,11 +38,13 @@ public void ForceRegisterOption(string key, object option) return default; } + /// public Dictionary RetrieveAllOptions() { return _options; } + /// public void Import(Dictionary options, bool overwrite = false) { if (overwrite) diff --git a/src/Navigator/Configuration/NavigatorOptionsCollectionExtensions.cs b/src/Navigator/Configuration/NavigatorOptionsCollectionExtensions.cs index 32a9a35..0ebe9e8 100644 --- a/src/Navigator/Configuration/NavigatorOptionsCollectionExtensions.cs +++ b/src/Navigator/Configuration/NavigatorOptionsCollectionExtensions.cs @@ -1,4 +1,5 @@ using System.Reflection; +using Telegram.Bot.Types; namespace Navigator.Configuration; @@ -11,62 +12,95 @@ public static class NavigatorOptionsCollectionExtensions private const string WebHookBaseUrlKey = "_navigator.options.webhook_base_url"; + /// + /// Sets the webhook base url. + /// + /// + /// public static void SetWebHookBaseUrl(this NavigatorOptions navigatorOptions, string webHookBaseUrl) { navigatorOptions.TryRegisterOption(WebHookBaseUrlKey, webHookBaseUrl); - } + /// + /// Retrieves the webhook base url + /// + /// + /// public static string? GetWebHookBaseUrl(this INavigatorOptions navigatorOptions) { return navigatorOptions.RetrieveOption(WebHookBaseUrlKey); } - + #endregion - + #region WebHookEndpoint private const string WebHookEndpointKey = "_navigator.options.webhook_endpoint"; + /// + /// Sets the webhook endpoint. + /// + /// + /// public static void SetWebHookEndpoint(this NavigatorOptions navigatorOptions, string webHookEndpoint) { navigatorOptions.TryRegisterOption(WebHookEndpointKey, webHookEndpoint); } + /// + /// Retrieves the webhook endpoint or a default one if not set. + /// + /// + /// public static string GetWebHookEndpointOrDefault(this INavigatorOptions navigatorOptions) { var webHookEndpoint = navigatorOptions.RetrieveOption(WebHookEndpointKey); if (webHookEndpoint is null) { - navigatorOptions.TryRegisterOption(WebHookEndpointKey,$"telegram/bot/{Guid.NewGuid()}"); + navigatorOptions.TryRegisterOption(WebHookEndpointKey, $"telegram/bot/{Guid.NewGuid()}"); } - + return navigatorOptions.RetrieveOption(WebHookEndpointKey)!; } #endregion - + #region MultipleActions private const string MultipleActionsKey = "_navigator.options.multiple_actions"; + /// + /// Enables the usage of multiple actions for one + /// + /// public static void EnableMultipleActionsUsage(this NavigatorOptions navigatorOptions) { navigatorOptions.TryRegisterOption(MultipleActionsKey, true); } + /// + /// Returns true if the usage of multiple actions for one is enabled. + /// + /// + /// public static bool MultipleActionsUsageIsEnabled(this INavigatorOptions navigatorOptions) { return navigatorOptions.RetrieveOption(MultipleActionsKey); } #endregion - + #region ActionsAssemblies private const string ActionsAssembliesKey = "_navigator.options.actions_assemblies"; + /// + /// Registers assemblies on which actions are available. + /// + /// + /// public static void RegisterActionsFromAssemblies(this NavigatorOptions navigatorOptions, params Assembly[] assemblies) { var registeredAssemblies = navigatorOptions.RetrieveOption(ActionsAssembliesKey); @@ -75,7 +109,7 @@ public static void RegisterActionsFromAssemblies(this NavigatorOptions navigator { var combinedAssemblies = new List(registeredAssemblies); combinedAssemblies.AddRange(assemblies); - + navigatorOptions.TryRegisterOption(ActionsAssembliesKey, combinedAssemblies); } else @@ -84,28 +118,41 @@ public static void RegisterActionsFromAssemblies(this NavigatorOptions navigator } } + /// + /// Returns the registered assemblies. + /// + /// + /// public static Assembly[] GetActionsAssemblies(this INavigatorOptions navigatorOptions) { - return navigatorOptions.RetrieveOption(ActionsAssembliesKey) ?? new[] { Assembly.GetCallingAssembly()}; + return navigatorOptions.RetrieveOption(ActionsAssembliesKey) ?? new[] { Assembly.GetCallingAssembly() }; } #endregion - + #region TelegramToken private const string TelegramTokenKey = "_navigator.options.telegram_token"; + /// + /// Configures de Telegram token. + /// + /// + /// public static void SetTelegramToken(this NavigatorOptions navigatorOptions, string telegramToken) { navigatorOptions.TryRegisterOption(TelegramTokenKey, telegramToken); - } + /// + /// Retrieves the Telegram token. + /// + /// + /// public static string? GetTelegramToken(this INavigatorOptions navigatorOptions) { return navigatorOptions.RetrieveOption(TelegramTokenKey); } - + #endregion - } \ No newline at end of file diff --git a/src/Navigator/Configuration/NavigatorRouteConfiguration.cs b/src/Navigator/Configuration/NavigatorRouteConfiguration.cs index 3b3d15c..1537ee2 100644 --- a/src/Navigator/Configuration/NavigatorRouteConfiguration.cs +++ b/src/Navigator/Configuration/NavigatorRouteConfiguration.cs @@ -1,18 +1,23 @@ using Microsoft.AspNetCore.Routing; -using Navigator.Configuration.Provider; namespace Navigator.Configuration; +/// +/// Configures the route for the telegram endpoint. +/// public class NavigatorRouteConfiguration { + /// + /// Endpoint Route Builder. + /// public IEndpointRouteBuilder EndpointRouteBuilder { get; internal set; } - - public NavigatorRouteProviderConfiguration ForProvider { get; internal set; } + /// + /// Default constructor. + /// + /// public NavigatorRouteConfiguration(IEndpointRouteBuilder endpointRouteBuilder) { EndpointRouteBuilder = endpointRouteBuilder; - - ForProvider = new NavigatorRouteProviderConfiguration(this); } } \ No newline at end of file diff --git a/src/Navigator/Configuration/Provider/NavigatorProviderConfiguration.cs b/src/Navigator/Configuration/Provider/NavigatorProviderConfiguration.cs deleted file mode 100644 index 7ea31de..0000000 --- a/src/Navigator/Configuration/Provider/NavigatorProviderConfiguration.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace Navigator.Configuration.Provider; - -/// -/// Provides a entry point for configuring new providers for Navigator. -/// -public class NavigatorProviderConfiguration -{ - private readonly NavigatorConfiguration _navigatorConfiguration; - - /// - /// Default constructor for . - /// - /// - public NavigatorProviderConfiguration(NavigatorConfiguration navigatorConfiguration) - { - _navigatorConfiguration = navigatorConfiguration; - } - - /// - /// Configure a new provider using this method. - /// - /// - /// - public NavigatorConfiguration Provider(Action<(NavigatorOptions Options, IServiceCollection Services)> configuration) - { - configuration.Invoke((_navigatorConfiguration.Options, _navigatorConfiguration.Services)); - - _navigatorConfiguration.RegisterOrReplaceOptions(); - - return _navigatorConfiguration; - } -} \ No newline at end of file diff --git a/src/Navigator/Configuration/Provider/NavigatorRouteProviderConfiguration.cs b/src/Navigator/Configuration/Provider/NavigatorRouteProviderConfiguration.cs deleted file mode 100644 index 2a29615..0000000 --- a/src/Navigator/Configuration/Provider/NavigatorRouteProviderConfiguration.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.AspNetCore.Routing; - -namespace Navigator.Configuration.Provider; - -public class NavigatorRouteProviderConfiguration -{ - private readonly NavigatorRouteConfiguration _navigatorRouteConfiguration; - - public NavigatorRouteProviderConfiguration(NavigatorRouteConfiguration navigatorRouteConfiguration) - { - _navigatorRouteConfiguration = navigatorRouteConfiguration; - } - - public NavigatorRouteConfiguration Provider(Action routeActions) - { - routeActions.Invoke(_navigatorRouteConfiguration.EndpointRouteBuilder); - - return _navigatorRouteConfiguration; - } -} \ No newline at end of file diff --git a/src/Navigator/Context/Accessor/INavigatorContextAccessor.cs b/src/Navigator/Context/Accessor/INavigatorContextAccessor.cs index 5c99139..e4a756c 100644 --- a/src/Navigator/Context/Accessor/INavigatorContextAccessor.cs +++ b/src/Navigator/Context/Accessor/INavigatorContextAccessor.cs @@ -1,6 +1,12 @@ namespace Navigator.Context.Accessor; +/// +/// Accessor for . +/// public interface INavigatorContextAccessor { + /// + /// Navigator Context. + /// INavigatorContext NavigatorContext { get; } } \ No newline at end of file diff --git a/src/Navigator/Context/Builder/INavigatorContextBuilder.cs b/src/Navigator/Context/Builder/INavigatorContextBuilder.cs index cd82dfa..8c2abae 100644 --- a/src/Navigator/Context/Builder/INavigatorContextBuilder.cs +++ b/src/Navigator/Context/Builder/INavigatorContextBuilder.cs @@ -2,7 +2,15 @@ namespace Navigator.Context.Builder; +/// +/// Navigator Context Builder. +/// public interface INavigatorContextBuilder { + /// + /// Builds a and returns it. + /// + /// + /// Task Build(Action configurationAction); } \ No newline at end of file diff --git a/src/Navigator/Context/Builder/NavigatorContextBuilder.cs b/src/Navigator/Context/Builder/NavigatorContextBuilder.cs index 0b2ff6a..8cbffdd 100644 --- a/src/Navigator/Context/Builder/NavigatorContextBuilder.cs +++ b/src/Navigator/Context/Builder/NavigatorContextBuilder.cs @@ -1,8 +1,9 @@ using Microsoft.AspNetCore.Components; using Microsoft.Extensions.Logging; +using Navigator.Bundled.Extensions.ActionType; +using Navigator.Bundled.Extensions.Update; using Navigator.Client; using Navigator.Context.Builder.Options; -using Navigator.Context.Builder.Options.Extensions; using Navigator.Entities; using Navigator.Extensions; using Navigator.Telegram; @@ -28,9 +29,9 @@ public NavigatorContextBuilder(ILogger logger, IEnumera public async Task Build(Action optionsAction) { optionsAction.Invoke(_options); - var actionType = _options.GetAcitonType() ?? throw new InvalidOperationException(); + var actionType = _options.GetActionType() ?? throw new InvalidOperationException(); - var conversation = _options.GetOriginalEventOrDefault()?.GetConversation() ?? throw new NavigationException(nameof(Conversation)); + var conversation = _options.GetUpdateOrDefault()?.GetConversation() ?? throw new NavigationException(nameof(Conversation)); INavigatorContext context = new NavigatorContext(_navigatorClient, await _navigatorClient.GetProfile(), actionType, conversation); diff --git a/src/Navigator/Context/Builder/Options/Extensions/NavigatorContextBuilderOptionsExtensions.cs b/src/Navigator/Context/Builder/Options/Extensions/NavigatorContextBuilderOptionsExtensions.cs deleted file mode 100644 index 43c8c9d..0000000 --- a/src/Navigator/Context/Builder/Options/Extensions/NavigatorContextBuilderOptionsExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Telegram.Bot.Types; - -namespace Navigator.Context.Builder.Options.Extensions; - -public static class NavigatorContextBuilderOptionsExtensions -{ - #region ActionType - - private const string ActionTypeKey = "_navigator.context.options.action_type"; - - public static void SetActionType(this INavigatorContextBuilderOptions contextBuilderOptions, string actionType) - { - contextBuilderOptions.TryRegisterOption(ActionTypeKey, actionType); - - } - - public static string? GetAcitonType(this INavigatorContextBuilderOptions contextBuilderOptions) - { - return contextBuilderOptions.RetrieveOption(ActionTypeKey); - } - - #endregion - - #region OriginalUpdate - - private const string OriginalEventKey = "_navigator.context.options.original_event"; - - public static void SetOriginalEvent(this INavigatorContextBuilderOptions contextBuilderOptions, Update originalUpdate) - { - contextBuilderOptions.TryRegisterOption(OriginalEventKey, originalUpdate); - - } - - public static Update? GetOriginalEventOrDefault(this INavigatorContextBuilderOptions contextBuilderOptions) - { - return contextBuilderOptions.RetrieveOption(OriginalEventKey); - } - - #endregion -} \ No newline at end of file diff --git a/src/Navigator/Context/Builder/Options/INavigatorContextBuilderOptions.cs b/src/Navigator/Context/Builder/Options/INavigatorContextBuilderOptions.cs index 194e562..c32b2cb 100644 --- a/src/Navigator/Context/Builder/Options/INavigatorContextBuilderOptions.cs +++ b/src/Navigator/Context/Builder/Options/INavigatorContextBuilderOptions.cs @@ -1,9 +1,36 @@ namespace Navigator.Context.Builder.Options; +/// +/// Navigator Context Builder Options. +/// public interface INavigatorContextBuilderOptions { + /// + /// Registers an option, fails if the option already exists. + /// + /// + /// + /// bool TryRegisterOption(string key, object option); + + /// + /// Registers an option, overriding any option that may exist. + /// + /// + /// void ForceRegisterOption(string key, object option); + + /// + /// Retrieves an option given a key. + /// + /// + /// + /// TType? RetrieveOption(string key); + + /// + /// Retrieves all options. + /// + /// Dictionary RetrieveAllOptions(); } \ No newline at end of file diff --git a/src/Navigator/Context/Builder/Options/NavigatorContextBuilderOptions.cs b/src/Navigator/Context/Builder/Options/NavigatorContextBuilderOptions.cs index 97b80d1..676159d 100644 --- a/src/Navigator/Context/Builder/Options/NavigatorContextBuilderOptions.cs +++ b/src/Navigator/Context/Builder/Options/NavigatorContextBuilderOptions.cs @@ -1,19 +1,25 @@ namespace Navigator.Context.Builder.Options; +/// public class NavigatorContextBuilderOptions : INavigatorContextBuilderOptions { private readonly Dictionary _options; + /// + /// Default constructor. + /// public NavigatorContextBuilderOptions() { _options = new Dictionary(); } + /// public bool TryRegisterOption(string key, object option) { return _options.TryAdd(key, option); } - + + /// public void ForceRegisterOption(string key, object option) { _options.Remove(key); @@ -21,6 +27,7 @@ public void ForceRegisterOption(string key, object option) TryRegisterOption(key, option); } + /// public TType? RetrieveOption(string key) { if (_options.TryGetValue(key, out var option)) @@ -31,6 +38,7 @@ public void ForceRegisterOption(string key, object option) return default; } + /// public Dictionary RetrieveAllOptions() { return _options; diff --git a/src/Navigator/Context/INavigatorContext.cs b/src/Navigator/Context/INavigatorContext.cs index 651a2b7..54dba55 100644 --- a/src/Navigator/Context/INavigatorContext.cs +++ b/src/Navigator/Context/INavigatorContext.cs @@ -3,12 +3,38 @@ namespace Navigator.Context; +/// +/// Navigator Context. +/// public interface INavigatorContext { + /// + /// Client to use for interacting with Navigator and the provider (Telegram). + /// public INavigatorClient Client { get; } + + /// + /// Profile of the bot in form. + /// Bot BotProfile { get; } + + /// + /// Installed extensions for + /// Dictionary Extensions { get; } + + /// + /// Useful items stored here. + /// Dictionary Items { get; } + + /// + /// Type of the action for this context. + /// public string ActionType { get; } + + /// + /// Conversation related to this context. + /// public Conversation Conversation { get; } } \ No newline at end of file diff --git a/src/Navigator/Context/INavigatorContextFactory.cs b/src/Navigator/Context/INavigatorContextFactory.cs index 134e844..b9b465f 100644 --- a/src/Navigator/Context/INavigatorContextFactory.cs +++ b/src/Navigator/Context/INavigatorContextFactory.cs @@ -7,7 +7,16 @@ namespace Navigator.Context; /// public interface INavigatorContextFactory { + /// + /// Supplies to the factory. + /// + /// + /// Task Supply(Action action); + /// + /// Retrieves a finished . + /// + /// INavigatorContext Retrieve(); } \ No newline at end of file diff --git a/src/Navigator/Entities/Bot.cs b/src/Navigator/Entities/Bot.cs index f8cd2b0..54af19c 100644 --- a/src/Navigator/Entities/Bot.cs +++ b/src/Navigator/Entities/Bot.cs @@ -5,7 +5,7 @@ namespace Navigator.Entities; /// /// Bot. /// -public record Bot(long Id, string Username, string FirstName) : User(Id, FirstName) +public record Bot(long Id, string FirstName) : User(Id, FirstName) { /// /// Whether the bot can join groups or not. diff --git a/src/Navigator/Entities/Chat.cs b/src/Navigator/Entities/Chat.cs index 7e9d86f..41c047d 100644 --- a/src/Navigator/Entities/Chat.cs +++ b/src/Navigator/Entities/Chat.cs @@ -31,12 +31,34 @@ public record Chat(long Id, Chat.ChatType Type) /// public bool? IsForum { get; init; } + /// + /// Type of Chat. + /// public enum ChatType { + /// + /// Private. + /// Private = 1, + + /// + /// Group. + /// Group = 2, + + /// + /// Channel. + /// Channel = 3, + + /// + /// Supergroup. + /// Supergroup = 4, + + /// + /// Sender. + /// Sender = 5 } } diff --git a/src/Navigator/Extensions/Bundled/NavigatorContextExtensions.cs b/src/Navigator/Extensions/Bundled/NavigatorContextExtensions.cs deleted file mode 100644 index 0cea741..0000000 --- a/src/Navigator/Extensions/Bundled/NavigatorContextExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Navigator.Context; -using Navigator.Extensions.Bundled.OriginalEvent; -using Telegram.Bot.Types; - -namespace Navigator.Extensions.Bundled; - -public static class NavigatorContextExtensions -{ - #region OriginalEvent - - - public static Update GetOriginalEvent(this INavigatorContext navigatorContext) - { - var update = navigatorContext.GetOriginalEventOrDefault(); - - return update ?? throw new NavigatorException("Update was not found."); - } - - public static Update? GetOriginalEventOrDefault(this INavigatorContext navigatorContext) - { - var @event = navigatorContext.Extensions.GetValueOrDefault(OriginalEventContextExtension.OriginalEventKey); - - if (@event is Update originalEvent) - { - return originalEvent; - } - - return default; - } - - #endregion -} \ No newline at end of file diff --git a/src/Navigator/Extensions/Bundled/OriginalEvent/OriginalEventContextExtension.cs b/src/Navigator/Extensions/Bundled/OriginalEvent/OriginalEventContextExtension.cs deleted file mode 100644 index 9f2cfdb..0000000 --- a/src/Navigator/Extensions/Bundled/OriginalEvent/OriginalEventContextExtension.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Navigator.Context; -using Navigator.Context.Builder.Options; -using Navigator.Context.Builder.Options.Extensions; - -namespace Navigator.Extensions.Bundled.OriginalEvent; - -internal class OriginalEventContextExtension : INavigatorContextExtension -{ - public const string OriginalEventKey = "_navigator.extensions.original_event"; - - public Task Extend(INavigatorContext navigatorContext, INavigatorContextBuilderOptions builderOptions) - { - navigatorContext.Extensions.TryAdd(OriginalEventKey, builderOptions.GetOriginalEventOrDefault()); - - return Task.FromResult(navigatorContext); - } -} \ No newline at end of file diff --git a/src/Navigator/Extensions/INavigatorContextExtension.cs b/src/Navigator/Extensions/INavigatorContextExtension.cs index 51a6238..0509ec7 100644 --- a/src/Navigator/Extensions/INavigatorContextExtension.cs +++ b/src/Navigator/Extensions/INavigatorContextExtension.cs @@ -3,7 +3,16 @@ namespace Navigator.Extensions; +/// +/// Implement this interface to extend +/// public interface INavigatorContextExtension { + /// + /// Extends . + /// + /// + /// + /// Task Extend(INavigatorContext navigatorContext, INavigatorContextBuilderOptions builderOptions); } \ No newline at end of file diff --git a/src/Navigator/NavigatorException.cs b/src/Navigator/NavigatorException.cs index 92fd54d..1a926e2 100644 --- a/src/Navigator/NavigatorException.cs +++ b/src/Navigator/NavigatorException.cs @@ -3,7 +3,7 @@ namespace Navigator; /// -/// TODO +/// Navigator exception. /// public class NavigatorException : Exception { diff --git a/src/Navigator/Old/NavigatorContextExtensions.cs b/src/Navigator/Old/NavigatorContextExtensions.cs deleted file mode 100644 index 3db54ea..0000000 --- a/src/Navigator/Old/NavigatorContextExtensions.cs +++ /dev/null @@ -1,257 +0,0 @@ -// using Navigator.Context; -// using Telegram.Bot.Types; -// using Telegram.Bot.Types.Enums; -// -// namespace Navigator.Old; -// -// /// -// /// Useful extensions for Navigator Context. -// /// -// public static class NavigatorContextExtensions -// { -// /// -// /// TODO -// /// -// /// -// /// -// public static NavigatorTelegramClient GetTelegramClient(this INavigatorContext context) -// { -// return context.Provider.GetTelegramClient(); -// } -// -// // #region TelegramUser -// // -// // /// -// // /// Get a Telegram user. -// // /// -// // /// -// // /// When user is not found. -// // /// -// // public static User GetTelegramUser(this INavigatorContext ctx) -// // { -// // var user = ctx.GetTelegramUserOrDefault(); -// // -// // return user ?? throw new Exception("User not found in update."); -// // } -// // -// // /// -// // /// Get a Telegram user or default if not found. -// // /// -// // /// -// // /// -// // public static User? GetTelegramUserOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type switch -// // { -// // UpdateType.Message => ctx.Update.Message.From, -// // UpdateType.InlineQuery => ctx.Update.InlineQuery.From, -// // UpdateType.ChosenInlineResult => ctx.Update.ChosenInlineResult.From, -// // UpdateType.CallbackQuery => ctx.Update.CallbackQuery.From, -// // UpdateType.EditedMessage => ctx.Update.EditedMessage.From, -// // UpdateType.ChannelPost => ctx.Update.ChannelPost.From, -// // UpdateType.EditedChannelPost => ctx.Update.EditedChannelPost.From, -// // UpdateType.ShippingQuery => ctx.Update.ShippingQuery.From, -// // UpdateType.PreCheckoutQuery => ctx.Update.PreCheckoutQuery.From, -// // _ => default -// // }; -// // } -// // -// // #endregion -// // -// #region Chat -// -// /// -// /// Gets a . -// /// -// /// -// /// When chat is not found. -// /// -// public static Chat GetTelegramChat(this INavigatorContext ctx) -// { -// var chat = ctx.GetTelegramChatOrDefault(); -// -// return chat ?? throw new Exception("Chat was not found."); -// } -// -// /// -// /// Get a Telegram chat or default if not found. -// /// -// /// -// /// Telegram Chat -// public static Chat? GetTelegramChatOrDefault(this INavigatorContext ctx) -// { -// return ctx.GetOriginalEventOrDefault()?.Type switch -// { -// UpdateType.CallbackQuery => ctx.GetOriginalEvent().CallbackQuery?.Message?.Chat, -// UpdateType.Message => ctx.GetOriginalEvent().Message?.Chat, -// UpdateType.EditedMessage => ctx.GetOriginalEvent().EditedMessage?.Chat, -// UpdateType.ChannelPost => ctx.GetOriginalEvent().ChannelPost?.Chat, -// UpdateType.EditedChannelPost => ctx.GetOriginalEvent().EditedChannelPost?.Chat, -// _ => default -// }; -// } -// -// #endregion -// // -// // #region Message -// // -// // /// -// // /// Get a Telegram message. -// // /// -// // /// -// // /// When message is not found. -// // /// -// // public static Message GetMessage(this INavigatorContext ctx) -// // { -// // return ctx.GetMessageOrDefault() ?? throw new Exception("Message not found in update."); -// // } -// // -// // /// -// // /// Get a Telegram message or default if not found. -// // /// -// // /// -// // /// -// // public static Message? GetMessageOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.Message ? ctx.Update.Message : default; -// // } -// // -// // #endregion -// // -// // #region InlineQuery -// // -// // /// -// // /// Get a Telegram inline query -// // /// -// // /// -// // /// When inline query is not found. -// // /// -// // public static InlineQuery GetInlineQuery(this INavigatorContext ctx) -// // { -// // return ctx.GetInlineQueryOrDefault() ?? throw new Exception("InlineQuery not found in update."); -// // } -// // -// // /// -// // /// Get a Telegram inline query or default if not found. -// // /// -// // /// -// // /// -// // public static InlineQuery? GetInlineQueryOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.InlineQuery ? ctx.Update.InlineQuery : default; -// // } -// // -// // #endregion -// // -// // #region ChosenInlineResult -// // -// // public static ChosenInlineResult GetChosenInlineResult(this INavigatorContext ctx) -// // { -// // return ctx.GetChosenInlineResultOrDefault() ?? throw new Exception("ChosenInlineResult not found in update."); -// // } -// // -// // public static ChosenInlineResult? GetChosenInlineResultOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.ChosenInlineResult ? ctx.Update.ChosenInlineResult : default; -// // } -// // -// // #endregion -// // -// // #region CallbackQuery -// // -// // public static CallbackQuery GetCallbackQuery(this INavigatorContext ctx) -// // { -// // return ctx.GetCallbackQueryOrDefault() ?? throw new Exception("CallbackQuery not found in update."); -// // } -// // -// // public static CallbackQuery? GetCallbackQueryOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.CallbackQuery ? ctx.Update.CallbackQuery : default; -// // } -// // -// // #endregion -// // -// // #region EditedMessage -// // -// // public static Message GetEditedMessage(this INavigatorContext ctx) -// // { -// // return ctx.GetEditedMessageOrDefault() ?? throw new Exception("EditedMessage not found in update."); -// // } -// // -// // public static Message? GetEditedMessageOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.EditedMessage ? ctx.Update.EditedMessage : default; -// // } -// // -// // #endregion -// // -// // #region ChannelPost -// // -// // public static Message GetChannelPost(this INavigatorContext ctx) -// // { -// // return ctx.GetChannelPostOrDefault() ?? throw new Exception("ChannelPost not found in update."); -// // } -// // -// // public static Message? GetChannelPostOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.ChannelPost ? ctx.Update.ChannelPost : default; -// // } -// // -// // #endregion -// // -// // #region EditedChannelPost -// // -// // public static Message GetEditedChannelPost(this INavigatorContext ctx) -// // { -// // return ctx.GetEditedChannelPostOrDefault() ?? throw new Exception("EditedChannelPost not found in update."); -// // } -// // -// // public static Message? GetEditedChannelPostOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.EditedChannelPost ? ctx.Update.EditedChannelPost : default; -// // } -// // -// // #endregion -// // -// // #region ShippingQuery -// // -// // public static ShippingQuery GetShippingQuery(this INavigatorContext ctx) -// // { -// // return ctx.GetShippingQueryOrDefault() ?? throw new Exception("ShippingQuery not found in update."); -// // } -// // -// // public static ShippingQuery? GetShippingQueryOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.ShippingQuery ? ctx.Update.ShippingQuery : default; -// // } -// // -// // #endregion -// // -// // #region PreCheckoutQuery -// // -// // public static PreCheckoutQuery GetPreCheckoutQuery(this INavigatorContext ctx) -// // { -// // return ctx.GetPreCheckoutQueryOrDefault() ?? throw new Exception("PreCheckoutQuery not found in update."); -// // } -// // -// // public static PreCheckoutQuery? GetPreCheckoutQueryOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.PreCheckoutQuery ? ctx.Update.PreCheckoutQuery : default; -// // } -// // -// // #endregion -// // -// // #region Poll -// // -// // public static Poll GetPoll(this INavigatorContext ctx) -// // { -// // return ctx.GetPollOrDefault() ?? throw new Exception("Poll not found in update."); -// // } -// // -// // public static Poll? GetPollOrDefault(this INavigatorContext ctx) -// // { -// // return ctx.Update.Type == UpdateType.Poll ? ctx.Update.Poll : default; -// // } -// // -// // #endregion -// } \ No newline at end of file diff --git a/src/Navigator/ServiceCollectionExtensions.cs b/src/Navigator/ServiceCollectionExtensions.cs index cbff4f6..eda29f5 100644 --- a/src/Navigator/ServiceCollectionExtensions.cs +++ b/src/Navigator/ServiceCollectionExtensions.cs @@ -1,20 +1,30 @@ using MediatR; using Microsoft.Extensions.DependencyInjection; using Navigator.Actions; +using Navigator.Bundled.Extensions.Update; using Navigator.Client; using Navigator.Configuration; using Navigator.Context; using Navigator.Context.Accessor; using Navigator.Context.Builder; using Navigator.Extensions; -using Navigator.Extensions.Bundled.OriginalEvent; using Navigator.Hosted; using Scrutor; namespace Navigator; +/// +/// Extensions for configuring Navigator. +/// public static class ServiceCollectionExtensions { + /// + /// Adds Navigator. + /// + /// + /// + /// + /// public static NavigatorConfiguration AddNavigator(this IServiceCollection services, Action options) { if (options == null) @@ -30,7 +40,7 @@ public static NavigatorConfiguration AddNavigator(this IServiceCollection servic services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); diff --git a/src/Navigator/Telegram/TelegramUpdateExtensions.cs b/src/Navigator/Telegram/TelegramUpdateExtensions.cs index 7387071..28bc8f7 100644 --- a/src/Navigator/Telegram/TelegramUpdateExtensions.cs +++ b/src/Navigator/Telegram/TelegramUpdateExtensions.cs @@ -71,8 +71,9 @@ public static Conversation GetConversation(this Update update) } var user = rawUser.IsBot - ? new Entities.Bot(rawUser.Id, rawUser.Username!, rawUser.FirstName) + ? new Entities.Bot(rawUser.Id, rawUser.FirstName) { + Username = rawUser.Username!, LastName = rawUser.LastName, LanguageCode = rawUser.LanguageCode, CanJoinGroups = rawUser.CanJoinGroups, diff --git a/src/Navigator/TelegramMiddleware.cs b/src/Navigator/TelegramMiddleware.cs index 011e543..4c4ea54 100644 --- a/src/Navigator/TelegramMiddleware.cs +++ b/src/Navigator/TelegramMiddleware.cs @@ -1,23 +1,32 @@ using Microsoft.Extensions.Logging; using Navigator.Actions; using Navigator.Bundled.Actions; -using Navigator.Bundled.Actions.Bundled; using Navigator.Bundled.Actions.Messages; using Navigator.Bundled.Actions.Updates; +using Navigator.Bundled.Extensions.ActionType; +using Navigator.Bundled.Extensions.Update; using Navigator.Context; -using Navigator.Context.Builder.Options.Extensions; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Payments; namespace Navigator; +/// +/// Telegram Middleware. +/// public class TelegramMiddleware { private readonly ILogger _logger; private readonly INavigatorContextFactory _navigatorContextFactory; private readonly IActionLauncher _actionLauncher; + /// + /// Default constructor. + /// + /// + /// + /// public TelegramMiddleware(ILogger logger, INavigatorContextFactory navigatorContextFactory, IActionLauncher actionLauncher) { _logger = logger; @@ -25,6 +34,10 @@ public TelegramMiddleware(ILogger logger, INavigatorContextF _actionLauncher = actionLauncher; } + /// + /// Processes an . + /// + /// public async Task Process(Update update) { var actionType = DefineActionType(update); @@ -37,7 +50,7 @@ public async Task Process(Update update) await _navigatorContextFactory.Supply(builder => { builder.SetActionType(actionType); - builder.SetOriginalEvent(update); + builder.GetUpdate(update); }); await _actionLauncher.Launch();