zeiteisen
zeiteisen

Reputation: 7168

Facebook Messanger Bot Webhook issue

I received this message

Your Webhooks subscription callback URL has not been accepting updates.

We've noticed that your Webhooks subscription for callback URL https://trololo.herokuapp.com/bot has not been accepting updates for at least 16 minutes. Please verify that your callback server is functioning so you may continue to receive updates. If you need to update your callback URL, see https://developers.facebook.com/docs/graph-api/reference/app/subscriptions#update

If your callback URL continues to fail to accept updates for 8 hours straight, we will disable your subscription. To reactivate the subscription, make a POST request with the same parameters, and it will be reactivated.

This code is executed on the server

app.post('/bot', function (req, res) {
  console.log('post bot: ' + req);
  var messaging_events = req.body.entry[0].messaging;
  for (var i = 0; i < messaging_events.length; i++) {
    var event = req.body.entry[0].messaging[i];
    var sender = event.sender.id;
    if (event.message && event.message.text) {
      text = event.message.text;
      console.log('text received: ' + text);
      sendTextMessage(sender, "Text received, echo: "+ text.substring(0, 200));
    }
  }
  res.sendStatus(200);
});

But it fails because req.body is undefined. The req params is also no json because it makes this error:

TypeError: Converting circular structure to JSON

req only shows [object Object] and I have no idea whats inside the object. .toString isn't working either.

I made the complete guide twice. I think the issue comes from the part were the facebook page should connect to the facebook app. I do this with curl -ik -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=<mytoken>" Please help. Any response is greatly appreciated.

Here is a demo log error logs

Upvotes: 3

Views: 1633

Answers (1)

ton
ton

Reputation: 4577

I think it's a dependency problem... maybe you're missing the json body parser body-parser

If you look at comments on program sample on node-wit/examples/messenger.js, you will see that you need install some deps:

in your project directory, try:

npm install body-parser express request

And look at: https://www.youtube.com/watch?v=zFO1cRr5-qY ... I think they resolved exactly this issue and others that you may find.

Upvotes: 1

Related Questions