ubershmekel
ubershmekel

Reputation: 12798

How can a Slack app communicate to the user why a slash command failed, and let the user edit the command?

When an app fails to handle a Slack slash command, the text is brought back to allow the user to edit it and immediately send it again. I have a slash-command that searches, but might fail to find any results. In that case, I would like the user to immediately be able to modify their search. The Slack docs explain that I should always return a 200 HTTP status, but then Slack also erases the command and the user can't immediately try again. When I tried to respond with a 404 status, the users get an alarming message like failed with the error "http_client_error". Is there a way to fail but also provide a custom message to the user why?

Upvotes: 3

Views: 1056

Answers (1)

Erik Kalkoken
Erik Kalkoken

Reputation: 32737

Yes, but you must not use HTTP status codes to community a failed search.

Just always return HTTP OK 200 and then add a response message telling the user what went wrong. You can do that by directly replying to the request from Slack within 3 seconds, or alternatively by sending a message to the response_url.

This is also clearly expressed in the offical documentation for slash commands:

Sending Error Responses

There are going to be times when you need to let the user know that something went wrong - perhaps the user supplied an incorrect text parameter alongside the command, or maybe there was a failure in an API being used to generate the command response.

It would be tempting in this case to return an HTTP 500 response to the initial command, but this isn't the right approach. The status code returned as a response to the command should only be used to indicate whether or not the request URL successfully received the data payload - while an error might have occurred in processing and responding to that payload, the communication itself was still successful. (Source)

As far as I know it is not possible to signal Slack that the user should be able to edit his last command though.

Upvotes: 2

Related Questions