Kyle H
Kyle H

Reputation: 3303

Slack API slash command - returns 502_service_error after the webhook is successfully used

I built a slash command that I run, my server responds using the webhook URL the slash command sends out, the message posts to the channel, but then Slack shows a private message saying "Darn - that slash command didn't work (error message: 502_service_error)"

What's going on that's making Slack think my command failed? I tried adding an immediate response and this error still happens.

The code is an AWS Lambda function, the Slash Command is calling an AWS API Gateway to access it.

Here's my Python code which uses requests to return the data -

response = requests.post(
    urllib.parse.unquote(response_hook), json={'attachments':[{'text': result, 'color': 'good'}], 'response_type': 'in_channel'},
    headers={'Content-Type': 'application/json'}
)

Upvotes: 3

Views: 3674

Answers (2)

ludichrislyts
ludichrislyts

Reputation: 57

The accepted answer is correct, Slack expects a '200' response with a slash command. Using the included 'callback' argument in the handler function of the lambda that receives the slash command works also.

callback(null);

The first argument to the callback is an error, so pass 'null' if ok. AWS doc Slack documentation

Upvotes: 0

Kyle H
Kyle H

Reputation: 3303

Ended up figuring out the answer after more digging. I needed to add a specific response at the end of my function that let Slack know the message was received successfully. Below is the Python code I used to do that which resolved the issue -

return { "isBase64Encoded": True, "statusCode": 200, "headers": { }, "body": "" }

You may have to enable Lambda Proxy Integration in your API Gateway settings for this to work, that was enabled by default for me though.

Upvotes: 7

Related Questions