Shane Shane - 5 months ago 643
Javascript Question

Facebook Messenger API: Trouble setting up a webhook

I am trying to set up a web hook for the new Facebook Messenger bot platform and am receiving this error:

The URL couldn't be validated. Response does not match challenge, expected value = '364011207', received='<html> <header> <s...'


The callback URL is SSL certified. I have created a .html file on the server which contains a script in the header with:

<script>
app.get('/webhook/', function (req, res) {
if (req.query['hub.verify_token'] === 'my_token_here') {
res.send(req.query['hub.challenge']);
}
res.send('Error, wrong validation token');
})




I have tried multiple variations and consulted the Facebook documentation on webhooks all day but am not having any success.

https://developers.facebook.com/docs/messenger-platform/quickstart
https://developers.facebook.com/docs/messenger-platform/webhook-reference#common_format

Any help is greatly appreciated.

Answer

I came across a fix. I scrapped my js attempt and created a new php file with the following code:

<?php

$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];

if ($verify_token === 'my_token_code') {
echo $challenge;
}

I got this code from the first 10 minutes of this video: https://www.facebook.com/marketingdevelopers/videos/883648801749520/

Still curious to know what i was doing wrong in my js attempt if anybody knows...

Comments