Exemple #1
0
        public async Task <SlackResult> HandleSlashCommandRequest(HttpRequest request, SlackEndpointConfiguration config)
        {
            if (request.Method != "POST")
            {
                return(new EmptyResult(HttpStatusCode.MethodNotAllowed));
            }

            await ReplaceRequestStreamWithMemoryStream(request).ConfigureAwait(false);

            var command = await DeserializeForm <SlashCommand>(request).ConfigureAwait(false);

            if (!VerifyRequest(await ReadString(request).ConfigureAwait(false), request.Headers, command.Token, config))
            {
                return(new StringResult(HttpStatusCode.BadRequest, "Invalid signature/token"));
            }

            return(await RespondAsync <SlashCommandResponse>(
                       r => _slashCommandHandler.Handle(command, r),
                       response => response == null
                       ?(SlackResult) new EmptyResult(HttpStatusCode.OK)
                       : new JsonResult(_jsonSettings, HttpStatusCode.OK, new SlashCommandMessageResponse(response)),
                       () => new EmptyResult(HttpStatusCode.OK)).ConfigureAwait(false));
        }