1

I'm trying to build a Facebook Messenger bot with Meteor. Setup includes looking for the Verify Token and respond with the challenge sent in the verification GET request. In Facebook's (non-Meteor) sample app, the following code is used:

app.get('/webhook', function(req, res) {
  if (req.query['hub.mode'] === 'subscribe' &&
      req.query['hub.verify_token'] === VALIDATION_TOKEN) {
    console.log("Validating webhook");
    res.status(200).send(req.query['hub.challenge']);
  } else {
    console.error("Failed validation. Make sure the validation tokens match.");
    res.sendStatus(403);          
  }  
});

When I try to achieve the same functionality using the following (Meteor) code, I receive the error below.

var bodyParser = Meteor.npmRequire( 'body-parser');

// Add two middleware calls. The first attempting to parse the request body as
// JSON data and the second as URL encoded data.
Picker.middleware( bodyParser.json() );
Picker.middleware( bodyParser.urlencoded( { extended: false } ) );

// ------------------------------------------------------------
// HANDLE THE INITIAL HANDSHAKE WITH FACEBOOK VIA A GET REQUEST
// ------------------------------------------------------------
var getRoutes = Picker.filter(function(req, res) {
  // you can write any logic you want.
  // but this callback does not run inside a fiber
  // at the end, you must return either true or false
  return req.method == "GET";
});

getRoutes.route('/webhook', function(params, req, res, next) {
  if (params.query['hub.verify_token'] === '78750') {
        console.log(params.query['hub.verify_token']);
        // res.end();
        res.end(params.query['hub.challenge']);
  }
}); // end getRoutes

Error:

The URL couldn't be validated. Response does not match challenge, expected value = '1127215706', received='<!DOCTYPE html> <htm...

Perhaps this issue is due to it being run on the client rather than the server? If so, where should I put this code in order for it to be run on the server?

In addition, my browser console has the following error 12 times:

Mixed Content: The page at 'https://pfbe.meteorapp.com/' was loaded over HTTPS, but requested an insecure font 'http://themes.googleusercontent.com/static/fonts/inconsolata/v5/BjAYBlHtW3CJxDcjzrnZCIbN6UDyHWBl620a-IRfuBk.woff'. This request has been blocked; the content must be served over HTTPS.

What can I do to fix this problem?

2
  • What do you mean by “it being run on the client rather than the server”? Facebook sends the request, so it is the client here, and your server is the one it is send to. // received='<!DOCTYPE html> … is pretty obvious - your endpoint returns a complete HTML document (whether it’s a default template, or perhaps an error document, can not be told from that snippet), and not just the challenge value as it is supposed to.
    – CBroe
    Jul 7, 2016 at 6:56
  • did you fixed ? or found a solution ? Apr 10, 2018 at 9:48

1 Answer 1

0

Use Restivus -You need to respond in the body with challenge and return it as a parsedInt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.