diff --git a/SlackNet.AspNetCore/MessageActionAdapter.cs b/SlackNet.AspNetCore/MessageActionAdapter.cs new file mode 100644 index 0000000..305e4c3 --- /dev/null +++ b/SlackNet.AspNetCore/MessageActionAdapter.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; +using SlackNet.Interaction; + +namespace SlackNet.AspNetCore +{ + class MessageActionAdapter : IMessageShortcutHandler + { + private readonly IMessageActionHandler _actionHandler; + public MessageActionAdapter(IMessageActionHandler actionHandler) => _actionHandler = actionHandler; + + public Task Handle(MessageShortcut request) => _actionHandler.Handle(request); + } +} \ No newline at end of file diff --git a/SlackNet.AspNetCore/SlackServiceConfiguration.cs b/SlackNet.AspNetCore/SlackServiceConfiguration.cs index 21f7631..be34dd2 100644 --- a/SlackNet.AspNetCore/SlackServiceConfiguration.cs +++ b/SlackNet.AspNetCore/SlackServiceConfiguration.cs @@ -252,6 +252,30 @@ public SlackServiceConfiguration RegisterMessageShortcutHandler(string callbackI public SlackServiceConfiguration RegisterMessageShortcutHandler(string callbackId, Func handlerFactory) => RegisterCompositeItem(p => new SpecificMessageShortcutHandler(callbackId, new ResolvedMessageShortcutHandler(p, s => new MessageShortcutHandlerAsyncWrapper(handlerFactory(s))))); + [Obsolete("Use RegisterMessageShortcutHandler instead")] + public SlackServiceConfiguration RegisterMessageActionHandler() + where THandler : class, IMessageActionHandler + { + _serviceCollection.TryAddScoped(); + return RegisterCompositeItem(p => new ResolvedMessageShortcutHandler(p, s => new MessageShortcutHandlerAsyncWrapper(new MessageActionAdapter(s.GetRequiredService())))); + } + + [Obsolete("Use RegisterMessageShortcutHandler instead")] + public SlackServiceConfiguration RegisterMessageActionHandler(IMessageActionHandler handler) => + RegisterCompositeItem(c => new MessageShortcutHandlerAsyncWrapper(new MessageActionAdapter(handler))); + + [Obsolete("Use RegisterMessageShortcutHandler instead")] + public SlackServiceConfiguration RegisterMessageActionHandler(Func handlerFactory) => + RegisterCompositeItem(p => new ResolvedMessageShortcutHandler(p, s => new MessageShortcutHandlerAsyncWrapper(new MessageActionAdapter(handlerFactory(s))))); + + [Obsolete("Use RegisterMessageShortcutHandler instead")] + public SlackServiceConfiguration RegisterMessageActionHandler(string callbackId) + where THandler : class, IMessageActionHandler + { + _serviceCollection.TryAddScoped(); + return RegisterCompositeItem(p => new SpecificMessageShortcutHandler(callbackId, new ResolvedMessageShortcutHandler(p, s => new MessageShortcutHandlerAsyncWrapper(new MessageActionAdapter(s.GetRequiredService()))))); + } + #endregion Message shortcuts #region Global shortcuts diff --git a/SlackNet.Tests/ServiceConfigurationLintTest.cs b/SlackNet.Tests/ServiceConfigurationLintTest.cs index 9cefead..8d4f0cc 100644 --- a/SlackNet.Tests/ServiceConfigurationLintTest.cs +++ b/SlackNet.Tests/ServiceConfigurationLintTest.cs @@ -57,6 +57,10 @@ public void StandardRegistrationMethods() ExpectReplaceMethod(publicMethods, nameof(SSC.ReplaceLegacyDialogSubmissionHandling), typeof(IDialogSubmissionHandler)); ExpectMethod(publicMethods, nameof(SSC.RegisterDialogSubmissionHandler), new[] { typeof(IDialogSubmissionHandler) }, new[] { typeof(string) }); + + // Backwards compatibility + ExpectRegistrationTriplet(publicMethods, nameof(SSC.RegisterMessageActionHandler), typeof(IMessageActionHandler), new Type[0], new Type[0]); + ExpectMethod(publicMethods, nameof(SSC.RegisterMessageActionHandler), new[] { typeof(IMessageActionHandler) }, new[] { typeof(string) }); // Experimental async API ExpectReplaceMethod(publicMethods, nameof(SSC.ReplaceAsyncBlockActionHandling), typeof(IAsyncBlockActionHandler)); diff --git a/SlackNet/Interaction/IMessageShortcutHandler.cs b/SlackNet/Interaction/IMessageShortcutHandler.cs index 9faa301..8b01b55 100644 --- a/SlackNet/Interaction/IMessageShortcutHandler.cs +++ b/SlackNet/Interaction/IMessageShortcutHandler.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; namespace SlackNet.Interaction { @@ -6,4 +7,10 @@ public interface IMessageShortcutHandler { Task Handle(MessageShortcut request); } + + [Obsolete("Use IMessageShortcutHandler instead")] + public interface IMessageActionHandler + { + Task Handle(MessageAction request); + } } \ No newline at end of file diff --git a/SlackNet/Interaction/MessageShortcut.cs b/SlackNet/Interaction/MessageShortcut.cs index 192fa22..7e96ba9 100644 --- a/SlackNet/Interaction/MessageShortcut.cs +++ b/SlackNet/Interaction/MessageShortcut.cs @@ -1,12 +1,16 @@ -using SlackNet.Events; +using System; +using SlackNet.Events; namespace SlackNet.Interaction { - [SlackType("message_action")] - public class MessageShortcut : InteractionRequest + [Obsolete("Use MessageShortcut instead")] + public class MessageAction : InteractionRequest { public string CallbackId { get; set; } public string TriggerId { get; set; } public MessageEvent Message { get; set; } } + + [SlackType("message_action")] + public class MessageShortcut : MessageAction { } } \ No newline at end of file