0

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?

Condorcho
  • 503
  • 4
  • 12
operator
  • 247
  • 1
  • 3
  • 15
  • 1
    What error_log() writes to, depends on the configuration. http://php.net/manual/en/errorfunc.configuration.php#ini.error-log (You can also call error_log() directly with the appropriate message_type and a filename.) – CBroe Mar 28 '17 at 11:15
  • Thanks, @CBroe. I'm now sending emails to my personal account with error_log but nothing has changed: no emails, no logs, no error triggered, no answer in the Messenger platform and still I don't have a way to debug it. – operator Mar 29 '17 at 09:24

0 Answers0