I want to subscribe to Slack Events API for any message posted in a slack channel. These are the following steps I took as given in Slack Event API documentations.
I made the user go through oauth authorization to install the app. The url is shown below with scope and redirect uri. (PHP Code)
$url = "https://slack.com/oauth/authorize/?client_id=" . SLACK_CLIENT_ID . "&scope=users.profile:read,users:read,groups:history,channels:history,im:history,mpim:history" . "&redirect_uri=" . urlencode('https://api.example.com/slack/oauth/callback') . "&state=XXXXXXXXX";
I receive a code from slack which I exchange for access token.
Access Token: xoxp-XXXXXXXXX-XXXXXXXXX-XXXXXXX-XXXXXXXXXXXXXXXXXXXX Scope: identify,channels:history,groups:history,im:history,mpim:history,users:read,users.profile:read Team Id: XXXXXXXX
I checked the apps and integration of the team to see if the app was installed and yes it is in the list of Apps.
Now as per my understanding when any message is posted in any channel of the team, a POST request should be made to my verified URL ( "https://api.example.com/slack/event/push"). But I don't get any POST request there.
I thought maybe the URL is broken but I tested it with a counter and every time the URL is hit it increments the counter. So the URL is fine.
Is there a step I missed somewhere? I don't know what to try next.
I contacted Slack support and they were very helpful. The logs at slack showed that Slack was actually sending POST requests to my Request url. So my setup worked fine. But my API framework was failing to parse the request body and hence sending internal server error (500) to Slack. We figured this out by using requestb.in.
All I had to do was change the way I parsed request body.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With