I'm trying to get events on my Symfony webapp when a new message is posted in a specific channel. Nothing too fancy, maybe storing the message in my MySQL database or simply displaying it. My true problem is that I don't really know where to start, how to handle the event or how to manipulate the data sent by Slack.
So far I've scoured Slack API's documentation but it doesn't provide language-specific guidelines (unlike Google's API for example). I've managed to register my Ngrok-fed URL (I'im in local development for now) to receive events and can see that my server is indeed receiving requests and payloads, I just don't know how to handle them. Really, I'm looking for a nudge in the right direction to get started.
I am receiving the Slack payload from a GET request and I can see the Slack message I'm trying to retrieve, but I don't know how to use it in my web application.
I have a function defined to the route I set on the Slack API to receive events:
/**
* @Route("/slack/handshake", methods={"GET", "POST"})
*/
public function getSlackHandshake () {
$rawData = file_get_contents('php://input');
$event = json_decode($rawData, true);
if (isset($event['challenge'])) {
$response = new Response(
$event['challenge'],
Response::HTTP_OK,
['content-type' => 'text/plain']
);
return $response->send();
} else {
$response = new Response(
'',
Response::HTTP_OK
);
// return $response->send();
return $this->redirectToRoute('slack_test', array('message' => $rawData));
}
}