Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Messenger API: Trouble setting up a webhook

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

The URL couldn't be validated. Response does not match challenge, expected value = '364011207', received='

Resources

https://developers.facebook.com/docs/messenger-platform/quickstart

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

Any help is greatly appreciated.

like image 736
Shane Avatar asked Apr 13 '16 10:04

Shane


People also ask

How do I set up webhooks on Facebook?

Configure the webhook for your app In the 'Webhooks' section of the Messenger settings console, click the 'Setup Webhooks' button. In the 'Callback URL' field, enter the public URL for your Facebook webhook.

How do I use webhook API?

With webhooks, it's generally a three-step process: Get the webhook URL from the application you want to send data to. Use that URL in the webhook section of the application you want to receive data from. Choose the type of events you want the application to notify you about.

Does Facebook use webhooks?

Webhooks allows you to receive real-time HTTP notifications of changes to specific objects in the Facebook Social Graph.


2 Answers

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/

like image 167
Shane Avatar answered Sep 19 '22 14:09

Shane


That code is node.js code and should be run on the server not in a <script> tag in your HTML.

Here's a simple walk through of setting up the messenger bot with node.js: https://github.com/voronianski/simon-le-bottle

Essentially you need to make sure you have a host that supports node.js applications and run it as such. It will not work inside of HTML.

like image 37
Jamund Ferguson Avatar answered Sep 19 '22 14:09

Jamund Ferguson