Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack bot interactive message payload not accessible

I have made a slack app that is hooked up to send a payload to my server upon a press of a button.

When the button is pressed, the payload is received by the server, which includes a JSON object, with a layout like this:

{  
   "type":"interactive_message",
   "actions":[ .. ],
   "callback_id":"wopr_game",
   "team":{ .. },
   "channel":{ .. },
   "user":{ .. },
   "action_ts":"1523126737.192039",
   "message_ts":"1523126734.000016",
   "attachment_id":"1",
   "token":"aYydBrSjjHHz4UqYXKB4tzDZ",
   "is_app_unfurl":false,
   "original_message":{ .. },
   "response_url":"https://hooks.slack.com/actions/T1ABCD2E12/330361579271/0dAEyLY19ofpLwxqozy3firz",
   "trigger_id":"342463876993.134749426887.e0c3b2e25d3a070b66361526a13be0bf"
}

However, I can't seem to access any of the variables inside the JSON object. Here's my express js code for the specific request.

router.post('/', function(req, res, next) {

    console.log(req.body['payload']) // prints json obj fine
    console.log(req.body['payload']['response_url']) // undefined

    res.send('Hello');
});

Am I missing something here?

like image 584
JC1 Avatar asked Apr 07 '18 19:04

JC1


1 Answers

Try looking at console.log(JSON.parse(req.body['payload'])['response_url'])

like image 56
Catalyst Avatar answered Sep 30 '22 05:09

Catalyst