Issue while trying to receive message notifications from Slack

Viewed 229

About

I am trying to receive message posted on my server as soon as user post message the message in group or channel or direct in slack.

App Status

enter image description here

Code in the verified file where challenge was posted.

header('Content-type: application/json');
$myfile = fopen("test.txt", "w") or die("Unable to open file!");
$data = json_decode(file_get_contents('php://input'), true);
fwrite($myfile, $data["challenge"]);
fclose($myfile);
$json = '{"challenge":' . $data["challenge"] . '}';
echo json_encode(["challenge" => $json]);

Question

Now that the above url has been verified successfully, I am still not able to receive the posted messages. I was expecting messages posted at same url which was used to verify challenge parameter. Is that correct?

Am I missing anything retrieving the messages posted on my server?

Update - 1

Due to some reasons I am not even able to verify the url anymore. My server is not receiving any data. I am trying to save whatever is being posted my side but it is always blank everytime,

1 Answers

I think your assumptions are correct.

According to slack documentation you should be receiving posts with the given payload in this endpoint:

https://api.slack.com/apis/connections/events-api#the-events-api__receiving-events__events-dispatched-as-json

I'm still unsure how are you validating that this isn't the case though, if you kept the code above you would see no result of the post data sent by slack, also if you don't return a response status 200, slack will stop posting to this endpoint after 1 hour.

https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events

Can you try adding test.php file something like:

<?php

// get all the POST requests
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    file_put_contents('test.json', json_encode($_POST, JSON_PRETTY_PRINT), FILE_APPEND);
    // return 200
    http_response_code(200);
    echo json_encode(["success" => true]);
    return;
}

At the very beginning, validate the url again and check if the requests start being saved on test.json.


Alternatively can you check if you web server is routing POST requests to this url?

Try using postman to validate that

Related