I am working on a small slack app development. I stuck in one situation. I am using slack dialog to get data from the user and when user enter data and click on submit button I get an alert message. I don't know what is it and why it gives an alert. What to do with this? Please note I get payload response in my interactive component script. And respond to the server with 200. Here is my Response code :
if($type == "dialog_submission")
{
http_response_code(200);
return json_encode(array(
'status' => 200,
'message' => 'ok'
));
$ch = curl_init("https://slack.com/api/chat.postMessage");
$dataSet = http_build_query([
"token" => $authToken,
"channel" => $data['channel']['name'],
"text" => "123",
]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataSet);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
You need to return an empty response to the Slack Dialog, or you will get the error
We had some trouble connecting. Try again?
So you must somewhere have an echo that returns something to the Slack dialog causing the error. You need to remove those. Like the echo $result;
at the end.
This error will also occur if your script has a run-time error, since it will then create an automatic response like "error in test.php line 101....". To check for that make sure you have error logging activated and check if there are any errors in the logfile.
You activate error logging by putting these commands at the beginning of your script:
ini_set("log_errors", 1);
ini_set("error_log", "php-errors.log");
You can however return validation errors to Slack, but those must be in a specific format. See this documentation for details.
Try something like:
if($type == "dialog_submission") {
return json_encode(array(
'status' => 200,
'message' => ''
));
}