I'm developing some code that answers via Facebook Messenger and I use this piece of code to handle the answer and answer back:
if(isset($_REQUEST['hub_verify_token'])) {
if ($_REQUEST['hub_verify_token'] === A::VERIFY_TOKEN) {
echo $_REQUEST['hub_challenge'];
exit;
}
}
$input = json_decode(file_get_contents('php://input'), TRUE);
$sender_id = $input['entry'][0]['messaging'][0]['sender']['id'];
$message_text = $input['entry'][0]['messaging'][0]['message']['text'];
$fb_handler = new FBHandler($sender_id);
/*$to_send = array(
'recipient' => array('id' => $sender_id ),
'message' => array('text' => "Hi" )
);*/
$to_send = $fb_handler->talk($message_text);
$ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.A::ACCESS_TOKEN);
curl_setopt_array($ch, array(
CURLOPT_POSTFIELDS => json_encode($to_send),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => array('Content-Type: application/json')
));
$response = curl_exec($ch);
error_log($response['error']);
curl_close($ch);
What I don't understand is why the commented $to_send
works but the non-commented not, because the code in the A
class is correct, it composes correctly the array.
So I came up with an idea and I'm asking you if it's correct (because I found nothing in the Facebook Developers documentation): is it possible that the array that will be sent to Messenger has to be composed in the same set of instructions?
I know it sounds ridiculous, but I dunno what else to think.
Also I noticed that error_log
doesn't work: nothing has been written in the php_errorlog
file. What's happening?