Reputation: 187
When there are no errors in the user's input, Slack requires a 200 OK
response and an empty body
.
I've tried various combinations of responses, including:
http_response_code(200);
header ('Content-Type: text/plain');
exit("");
and:
http_response_code(200);
exit();
and:
header("HTTP/1.1 200 OK");
exit("");
But, the user's dialog always says:
"We had some trouble connecting. Try again?"
Note: when I send an error using JSON, the dialog displays as expected.
Upvotes: 1
Views: 241
Reputation: 2146
I had this same error, though only on certain scenarios when updating modals.
The answer boiled down to me wanting to track success/fail on the send and I was returning a message back to my other functions.
if (!empty($route)) {
$slack_response = json_decode(curlslack($route, $body, '', false, $token));
if (!empty($slack_response)) {
$return = ['error' => false, 'message' => "Slack Message Sent", "slack_response" => $slack_response];
}
}
}
exit(); //******** This fixed the issue (though I could just as soon removed the return below.....)
//NOTE: we CANNOT return data here! Slack requires an EMPTY message - and enforces it only on some scenarios.....
return json_encode($return);
I'll put a different bit of code in my app to return the data and only print it when I need it (for user verification), but not allow it when it comes from Slack, though I thought it might be helpful for others to see this is certainly something you need to pay attention to - do not send anything back to Slack!
Upvotes: 0
Reputation: 187
The header
was not the issue. As @ErikKalkoken mentioned in a comment, a simple exit()
is appropriate. The issue was an included file had two returns after the closing tag. Like so:
Interestingly, a single return does not trip up the Slack API.
Upvotes: 1