public void OnRequestBegin(SlackRequestContext context) { context[nameof(SlackRequestContext.ServiceProvider)] = _serviceProvider; context[nameof(SlackRequestContext.EventHandlers)] = new HandlerCollection <IEventHandler>(context, _eventHandlers); context[nameof(SlackRequestContext.BlockActionHandlers)] = new HandlerCollection <IAsyncBlockActionHandler>(context, _blockActionHandlers); context[nameof(SlackRequestContext.BlockOptionProviders)] = new HandlerIndex <IBlockOptionProvider>(context, _blockOptionProviders); context[nameof(SlackRequestContext.MessageShortcutHandlers)] = new HandlerCollection <IAsyncMessageShortcutHandler>(context, _messageShortcutHandlers); context[nameof(SlackRequestContext.GlobalShortcutHandlers)] = new HandlerCollection <IAsyncGlobalShortcutHandler>(context, _globalShortcutHandlers); context[nameof(SlackRequestContext.ViewSubmissionHandlers)] = new HandlerIndex <IAsyncViewSubmissionHandler>(context, _viewSubmissionHandlers); context[nameof(SlackRequestContext.SlashCommandHandlers)] = new HandlerIndex <IAsyncSlashCommandHandler>(context, _slashCommandHandlers); context[nameof(SlackRequestContext.WorkflowStepEditHandlers)] = new HandlerCollection <IAsyncWorkflowStepEditHandler>(context, _workflowStepEditHandlers); context[nameof(SlackRequestContext.LegacyInteractiveMessageHandlers)] = new HandlerIndex <IInteractiveMessageHandler>(context, _legacyInteractiveMessageHandlers); context[nameof(SlackRequestContext.LegacyOptionProviders)] = new HandlerIndex <IOptionProvider>(context, _legacyOptionProviders); context[nameof(SlackRequestContext.LegacyDialogSubmissionHandlers)] = new HandlerIndex <IDialogSubmissionHandler>(context, _legacyDialogSubmissionHandlers); }
private async Task <Unit> HandleRequest(SocketEnvelope envelope) { try { var requestContext = new SlackRequestContext(); await _requestListener.OnRequestBegin(requestContext).ConfigureAwait(false); var responded = false; try { await HandleSpecificRequest(requestContext, envelope, Respond).ConfigureAwait(false); } finally { if (!responded) { Respond(new Acknowledgement { EnvelopeId = envelope.EnvelopeId }); } await _requestListener.OnRequestEnd(requestContext).ConfigureAwait(false); } void Respond(object payload) { responded = true; var ack = payload == null ? new Acknowledgement() : new Acknowledgement <object> { Payload = payload }; ack.EnvelopeId = envelope.EnvelopeId; Send(ack); } } catch { // ignored } return(Unit.Default); }
private Task HandleSpecificRequest(SlackRequestContext requestContext, SocketEnvelope envelope, Action <object> respond) => envelope switch {
public Task OnRequestEnd(SlackRequestContext context) => Task.CompletedTask;