Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My request URL is not receiving any events for the Slack Events API. What am I missing?

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.

  1. I created a slack app with following permission scopes :
    • channels:history, groups:history, im:history, mpim:history
  2. In Event Subscriptions, I enabled events, verified Request URL ( "https://api.example.com/slack/event/push") successfully, and subscribed to the following Team Events :
    • channel_history_changed, group_history_changed, message.channels, message.groups, message.im, message.mpim
  3. 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";

  4. 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.

like image 541
Suba S Avatar asked Nov 19 '22 03:11

Suba S


1 Answers

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.

like image 92
Suba S Avatar answered Dec 25 '22 23:12

Suba S