jeudi 8 février 2018

BotMan: Can't get facebook messenger recipient

I want to fill the $recipient variable with the Facebook messenger recipient. I have this code snippet:

   $payload1 = $bot->getMessage()->getPayload();
    if(array_key_exists($payload1['recipient'])){
        $recipient = $payload1['recipient']['id']
        if($recipient == '1718785685111526'){
            $bot->reply('I am the Test bot');
        }
    }
    $user = $bot->getUser()->getInfo();
    $drive = json_encode($bot->getDriver());

    $rawpayload1 = json_encode($payload1);
    $rawuser = json_encode($user);

    DB::insert("INSERT INTO `chat_raw_data` (rawdata) VALUES ('$rawpayload1')" );
    DB::insert("INSERT INTO `chat_raw_data` (rawdata) VALUES ('$rawuser')" );
    DB::insert("INSERT INTO `chat_raw_data` (rawdata) VALUES ('$drive')" );
    $bot->reply('Success');

My problem: If I don't comment out the if section, the bot doesn't work.

The ouptut of the json_encode($payload1) is

{"sender":{"id":"1850104945030757"},"recipient":{"id":"1718785685111526"},"timestamp":1518101626559,"message":{"mid":"mid.$cAAZBzICzc0Fnpy3Gv1hdeh-W9pFq","seq":166174,"text":"testmessage"}}

Why it isn't working?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire