Search code examples
facebookfacebook-messenger-botfacebook-webhooks

Send a message to a person, who added a comment on Page


I wanna create a similar thing, that is described here for my business page on facebook. There are lots of alternatives like chatfuel and manychat, but I wanna have the same Auto PM, but more flexible. What I did so far, I connected to: webhooks and messenger APIs. I wrote these lines of code, which allow me to see all changes in the feed of my Business Page.

app.post("/api/webhooks", jsonParser, (req, res) => {
    const jsonBody = req.body || '';
    if (typeof jsonBody !== 'object' || !jsonBody.entry || jsonBody.object !== 'page') { return res.send('no body'); }
    // else
    const { message, sender_id } = jsonBody.entry[0].changes[0].value;
    console.log(message);
    if (!message) { return res.send('no message'); }
    bot.say(sender_id, 'hey there, Mr. P!');
    return res.send('post request');
});

As I said this piece of code allows me to see, who made changes on my business page, so I can take even user's id. So I thought, if I know user's ID I can send him a message, but I get the error below, when I'm trying to send a message.

{ message: '(#100) No matching user found',
  type: 'OAuthException',
  code: 100,
  error_subcode: 2018001,
  fbtrace_id: 'CkNJQpdP6A9' }

What I'm doing wrong? Do I need maybe more permissions for some actions?


Solution

  • Actually, I found how to resolve this thing and it's pretty easy to do. Facebook docs: https://developers.facebook.com/docs/graph-api/reference/v2.9/object/private_replies