Jump to content
php.lv forumi

Edgars Po

Reģistrētie lietotāji
  • Content Count

    1
  • Joined

  • Last visited

About Edgars Po

  • Rank
    Māceklis

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Edgars Po

    FB PHP chatbot

    Sveiki visi Interesejos par fb chatbotu darbibu tiesi PHP.Atradu visadus Python un savadakas iespejas ka izveidot sakarigu botu kas spej “macities” darbibas princips,ka teiksim bots Replica. Kas jauniegutu informaciju saglaba faila un failu izmanto jautajumu atpazisanai un atbildes piemeklesanai.Varbut kads var palidzet ar piemeru?Sobrid kods ir vienkars: // parameters $hubVerifyToken = 'Your token'; $accessToken = "Your acces token"; // check token at setup if ($_REQUEST['hub_verify_token'] === $hubVerifyToken) { echo $_REQUEST['hub_challenge']; exit; } // handle bot's anwser $input = json_decode(file_get_contents('php://input'), true); $senderId = $input['entry'][0]['messaging'][0]['sender']['id']; $messageText = $input['entry'][0]['messaging'][0]['message']['text']; $response = null; //set Message if($messageText == "hi") { $answer = "Hello"; } //send message to facebook bot $response = [ 'recipient' => [ 'id' => $senderId ], 'message' => [ 'text' => $answer ] ]; $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$accessToken); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); if(!empty($input)){ $result = curl_exec($ch); } curl_close($ch);
×