Skip to content

Commit

Permalink
SlackRequestHandler logs incoming request bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
soxtoby committed Aug 10, 2023
1 parent ef350c3 commit fef28c0
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions SlackNet.AspNetCore/SlackRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public Task<SlackResult> HandleEventRequest(HttpRequest request, SlackEndpointCo
}

var requestBody = await ReadString(request).ConfigureAwait(false);

_log.WithContext("RequestBody", requestBody)
.Data("Received event request");

var eventRequest = DeserializeEventRequest(requestBody);

if (eventRequest is null)
Expand Down Expand Up @@ -113,13 +117,18 @@ public Task<SlackResult> HandleActionRequest(HttpRequest request, SlackEndpointC

var interactionRequest = await DeserializePayload<InteractionRequest>(request).ConfigureAwait(false);

var requestBody = await ReadString(request).ConfigureAwait(false);

_log.WithContext("RequestBody", requestBody)
.Data("Received action request");

if (interactionRequest is null)
{
_log.Internal("Unrecognized action request content");
return StringResult(HttpStatusCode.BadRequest, "Unrecognized content");
}

return RequestValidation(await ReadString(request).ConfigureAwait(false), request.Headers, interactionRequest.Token, config)
return RequestValidation(requestBody, request.Headers, interactionRequest.Token, config)
?? await HandleAction(requestContext, interactionRequest).ConfigureAwait(false);
});

Expand Down Expand Up @@ -244,13 +253,18 @@ public Task<SlackResult> HandleOptionsRequest(HttpRequest request, SlackEndpoint

var optionsRequest = await DeserializePayload<OptionsRequestBase>(request).ConfigureAwait(false);

var requestBody = await ReadString(request).ConfigureAwait(false);

_log.WithContext("RequestBody", requestBody)
.Data("Received options request");

if (optionsRequest == null)
{
_log.Internal("Unrecognized options request content");
return StringResult(HttpStatusCode.BadRequest, "Unrecognized content");
}

return RequestValidation(await ReadString(request).ConfigureAwait(false), request.Headers, optionsRequest.Token, config)
return RequestValidation(requestBody, request.Headers, optionsRequest.Token, config)
?? optionsRequest switch
{
OptionsRequest legacyOptionsRequest => await HandleLegacyOptionsRequest(requestContext, legacyOptionsRequest).ConfigureAwait(false),
Expand Down Expand Up @@ -295,13 +309,18 @@ public Task<SlackResult> HandleSlashCommandRequest(HttpRequest request, SlackEnd

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

var requestBody = await ReadString(request).ConfigureAwait(false);

_log.WithContext("RequestBody", requestBody)
.Data("Received slash command request");

if (command is null)
{
_log.Internal("Unrecognized slash command request content");
return StringResult(HttpStatusCode.BadRequest, "Unrecognized content");
}

return RequestValidation(await ReadString(request).ConfigureAwait(false), request.Headers, command.Token, config)
return RequestValidation(requestBody, request.Headers, command.Token, config)
?? await RespondAsync<SlashCommandResponse>(r =>
{
var handler = _handlerFactory.CreateSlashCommandHandler(requestContext);
Expand Down

0 comments on commit fef28c0

Please sign in to comment.