I have relatively simple Facebook Messenger bot in php for research purposes:
$access_token = "xxxxxxx";
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];
if ($verify_token === 'MY_VERIFICATION_TOKEN') {
echo $challenge;
}
$input = json_decode(file_get_contents('php://input'), true);
$sender = $input['entry'][0]['messaging'][0]['sender']['id'];
$message = $input['entry'][0]['messaging'][0]['message']['text'];
$url = 'https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token.';
$ch = curl_init($url);
if($message=="hi")
{
$jsonData = '{
"recipient":{
"id":"'.$sender.'"
},
"message":{
"text":"hello!"
}
}';
}
$jsonDataEncoded = $jsonData;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
and my cron job is same as in developer guide
curl -ik -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=xxxxxx"
So basically, nothing besides connection and one response. When i personally send "hi" (as a page owner and app owner), my bot always responds correctly, but when other people try to say hi - bot sometimes responds, sometimes not (usually not, in 5 cases bot responded once)
Additionally, when i visit my script url, it gives me error:
{"error":{"message":"(#100) The parameter recipient is required","type":"OAuthException","code":100,"fbtrace_id":"DvrO1UEw5BJ"}}
Please help me to set this right.