33using Slackbot . Net . Endpoints . Abstractions ;
44using Slackbot . Net . Endpoints . Models . Interactive ;
55using Slackbot . Net . Endpoints . Models . Interactive . BlockActions ;
6+ using Slackbot . Net . Endpoints . Models . Interactive . MessageActions ;
67using Slackbot . Net . Endpoints . Models . Interactive . ViewSubmissions ;
78
89namespace Slackbot . Net . Endpoints . Middlewares ;
@@ -13,14 +14,20 @@ internal class InteractiveEvents
1314 private readonly ILogger < InteractiveEvents > _logger ;
1415 private readonly IEnumerable < IHandleViewSubmissions > _responseHandlers ;
1516 private readonly IEnumerable < IHandleInteractiveBlockActions > _blockActionHandlers ;
17+ private readonly IEnumerable < IHandleMessageActions > _messageActionHandlers ;
1618 private readonly NoOpViewSubmissionHandler _noOp ;
1719
18- public InteractiveEvents ( RequestDelegate next , ILogger < InteractiveEvents > logger , IEnumerable < IHandleViewSubmissions > responseHandlers , IEnumerable < IHandleInteractiveBlockActions > blockActionHandlers , ILoggerFactory loggerFactory )
20+ public InteractiveEvents ( RequestDelegate next , ILogger < InteractiveEvents > logger ,
21+ IEnumerable < IHandleViewSubmissions > responseHandlers ,
22+ IEnumerable < IHandleInteractiveBlockActions > blockActionHandlers ,
23+ IEnumerable < IHandleMessageActions > messageActionHandlers ,
24+ ILoggerFactory loggerFactory )
1925 {
2026 _next = next ;
2127 _logger = logger ;
2228 _responseHandlers = responseHandlers ;
2329 _blockActionHandlers = blockActionHandlers ;
30+ _messageActionHandlers = messageActionHandlers ;
2431 _noOp = new NoOpViewSubmissionHandler ( loggerFactory . CreateLogger < NoOpViewSubmissionHandler > ( ) ) ;
2532 }
2633
@@ -43,12 +50,40 @@ public async Task Invoke(HttpContext context)
4350 } ;
4451 await context . Response . WriteAsync ( res . Response ) ;
4552 break ;
53+ case InteractionTypes . MessageAction :
54+ await HandleMessageAction ( payload as MessageActionInteraction ) ;
55+ break ;
4656 default :
4757 await _noOp . Handle ( payload ) ;
4858 break ;
4959 }
5060 }
5161
62+ private async Task HandleMessageAction ( MessageActionInteraction messageAction )
63+ {
64+ var handler = _messageActionHandlers . FirstOrDefault ( ) ;
65+
66+ if ( handler == null )
67+ {
68+ _logger . LogError ( $ "No handler registered for { nameof ( MessageActionInteraction ) } interactions") ;
69+ await _noOp . Handle ( messageAction ) ;
70+ }
71+ else
72+ {
73+ _logger . LogInformation ( $ "Handling using { handler . GetType ( ) } ") ;
74+ try
75+ {
76+ _logger . LogInformation ( $ "Handling using { handler . GetType ( ) } ") ;
77+ var response = await handler . Handle ( messageAction ) ;
78+ _logger . LogInformation ( response . Response ) ;
79+ }
80+ catch ( Exception e )
81+ {
82+ _logger . LogError ( e , e . Message ) ;
83+ }
84+ }
85+ }
86+
5287 private async Task < EventHandledResponse > HandleBlockActions ( BlockActionInteraction payload )
5388 {
5489 var handler = _blockActionHandlers . FirstOrDefault ( ) ;
0 commit comments