Search code examples
phpfacebookfacebook-graph-apiwampserverwebhooks

Receiving multiple webhook notification for Facebook Feed


I am facing issue with Facebook Webhook for feed while messages are working perfectly. For one post i keep on getting multiple notification from Facebook. I have already raised a bug with Facebook and their team is saying that my server is failing to send back 200 OK HTTP status. Also in their doc i have found that

"Your webhook callback should always return a 200 OK HTTP response when invoked by Facebook. Failing to do so may cause your webhook to be unsubscribed by the Messenger Platform."

My code goes like this:

<?php
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];

if ($verify_token === 'password')
{
echo $challenge;

}

/*........RECEIVING INPUT FROM fACEBOOK.........*/
$input = json_decode(file_get_contents('php://input') , true);
error_log(print_r($input, true));

/*after this i am calling AI and then replying back*/

Is there any way to send back 200 OK status before calling AI in php.


Solution

  • For the Workaround, I have stored the notification in DB and for every notification i am checking existing data (timestamp, senderId, post) in the DB to eliminate the duplicate post.

    If anyone is having better option in terms of complexity please let us know.