1

Hi i am trying to catch the message delivered JSON response from Facebook messenger for my bot so that I can send follow up messages when I know a gallery of images has been rendered.

I have read (https://developers.facebook.com/docs/messenger-platform/webhook-reference/message-delivered) and can see the message delivered JSON.

{
   "sender":{
      "id":"USER_ID"
   },
   "recipient":{
      "id":"PAGE_ID"
   },
   "delivery":{
      "mids":[
         "mid.1458668856218:ed81099e15d3f4f233"
      ],
      "watermark":1458668856253,
      "seq":37
   }
}

I have subscribed to the message delivery webhook also.

I have written code to catch the message delivery JSON but with no luck :

// handler receiving messages
app.post('/webhook', function (req, res) {

     if(req.hasOwnProperty('watermark')){
       console.log('message delivery found');
     }
}

Any help would be much appreciated.

Ethan Richardson
  • 461
  • 2
  • 10
  • 28

1 Answers1

1

I would just comment but im new here :)

im not sure if you are using bodyparser or not but i would inspect the req.body like bellow

// add this to the app file

var bodyParser = require('body-parser');
app.use(bodyParser.json());

app.post('/webhook', function (req, res) {
    console.log(req.body); // inspect the body data
    if(req.body.delivery && req.body.delivery.watermark)
        console.log('message delivery found');
    }
}
Jacob
  • 86
  • 2