0

I need to understand how the FB Webhooks works. I set up a Webhook for the new Facebook Messenger following the guide and all works like a charm:

I create a GET endpoint to receive the connect the API for the first time:

router.get('/fb_cb', function(req, res, next) {
    if (req.query['hub.verify_token'] === 'my_token') {
        res.send(req.query['hub.challenge']);
        console.log('fb GET!');
    } else {
        res.send('Error, wrong validation token');    
    }
});

In my Fb pane I reached this endpoint for the first time, setting up the page, get the Page Access Token end set up an endpoint to receive the callback:

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

    console.log('hook');
    messaging_events = req.body.entry[0].messaging;
        for (i = 0; i < messaging_events.length; i++) {
            event = req.body.entry[0].messaging[i];
            sender = event.sender;
            if (event.message && event.message.text) {
                console.log(event.sender.id);
            }
        }
    res.sendStatus(200);
});

and all it's ok, I can chat with my page :D

Now I'm trying to do the same thing for receive user updates, so I configured the endpoint in Facebook Webhooks, and GET endpoint is reached without problems. BUT, I don't receive any notification by my user when I do any action like posting content, changing personal status…

This is the current state of my subscriptions retrieved by Graph API:

data: [{
    object: "user",
    callback_url: "https://myapp.com/fb_cb",
    fields: ["about", "about_me", "current_location", "likes", "photos", "pic", "picture", "status", "statuses", "work"],
    active: true
}, {
    object: "page",
    callback_url: "https://myapp.com/fb_messenger_cb",
    fields: ["message_deliveries", "messages", "messaging_optins", "messaging_postbacks"],
    active: true
}, {
    object: "application",
    callback_url: "https://myapp.com/fb_app_cb",
    fields: ["async_requests"],
    active: true
}]

There is a way to achieve this result? What's wrong?

shaithana
  • 2,470
  • 1
  • 24
  • 37
  • "Now I'm trying to do the same thing for receive user updates" .. Chat bot API was never meant to get User updates. I'm not sure if you can do that using any FB API because the User ID (sender Id) we get on our webhook is just for the scope of the App-page and is completely different than the actual Facebook userid. – Mukarram Khalid May 06 '16 at 05:54
  • @MukarramKhalid I know that chat bot isn't for User updates, but I'm try to use the "Webhooks" (the section immediately before the "Messenger" in dashboard). So what's the scope of this Webhooks? I need to replicate the function that links FB and Twitter, where the user post on Facebook is post is published in Twitter also… thanks for any info. – shaithana May 06 '16 at 08:21
  • Currently, this is the only information you can get about the user from the Sender Id. From the docs: first_name,last_name,profile_pic,locale,timezone,gender. More information here : https://developers.facebook.com/docs/messenger-platform/implementation#user_profile_api There's a workaround where you can ask the user to login using the FB login API to get the actual User Id and then link the two IDs at your end. But that won't be the ideal way to do it. – Mukarram Khalid May 06 '16 at 08:57
  • @MukarramKhalid can you explain more about the workaround (maybe a link)? – shaithana May 06 '16 at 09:17
  • 1
    Honestly .. I haven't seen a working example yet but there are some ideas discussed on this question .. http://stackoverflow.com/questions/36598365/identifying-facebook-messenger-user-with-userid-from-a-facebook-login .. This also answers your question .. http://stackoverflow.com/questions/36832020/facebook-messenger-platform-how-to-get-user-specific-information – Mukarram Khalid May 06 '16 at 09:39

0 Answers0