Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(1);
- $servername = "localhost";
- $username = "####";
- $password = "####";
- $dbname = "ajsearch";
- $datatable = "atbible";
- // parameters
- $hubVerifyToken = '#####################';
- $accessToken = "############################################################";
- // 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 there! :)";}
- if($messageText == "Hi") { $answer = "Hello there! :)";}
- if($messageText == "amen") {$answer = "Namaste' ";}
- if($messageText == "Amen") {$answer = "Namaste' ";}
- if($messageText == "help") {
- $answer = "Typing !bookcha:pter (ie; !John3:16 would enable John 3:16 -Thank you!";}
- if($messageText == "Help") {
- $answer = "Typing !bookcha:pter (ie; !John3:16 would enable John 3:16 -Thank you!";}
- if($messageText == "!John3:16") {$answer = "For God had such love for the world that he gave his only Son, so that whoever has faith in him may not come to destruction but have eternal life.";}
- if($messageText == "info") {$answer = "Abbreviate Bible Book Names usually as a Four Character Reference. I will have a list to use as soon as possible. :)";}
- if($messageText == "Info") {$answer = "Abbreviate Bible Book Names usually as a Four Character Reference. I will have a list to use as soon as possible. :)";}
- //$rem = "$messengerText . $otherstring";
- //if(strpos( "x".$messageText, '!' ) !== false ) ;
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- //$messageText = "!Ecc1:1";
- list($msgat, $message) = explode("!", $messageText, 2);
- $sql = "SELECT verse FROM ".$datatable." WHERE book LIKE '%".$message."'";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- //send message to facebook bot
- }
- if ($msgat == "!")
- {
- //*// THIS has not been working.
- $answer = (" " . $row["verse"]); //this will store value into single variable answer
- }
- $response = [
- 'recipient' => [ 'id' => $senderId ],
- 'message' => [ 'text' => $answer ]
- ];
- //needed for else? "}"?
- }
- else {
- $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);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement