Advertisement
x1705

mybot2

Feb 18th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. <?php
  2. error_reporting(1);
  3. $servername = "localhost";
  4. $username = "####";
  5. $password = "####";
  6. $dbname = "ajsearch";
  7. $datatable = "atbible";
  8.  
  9.  
  10. // parameters
  11. $hubVerifyToken = '#####################';
  12. $accessToken = "############################################################";
  13.  
  14. // check token at setup
  15. if ($_REQUEST['hub_verify_token'] === $hubVerifyToken) {
  16. echo $_REQUEST['hub_challenge'];
  17. exit;
  18. }
  19.  
  20. // handle bot's anwser
  21. $input = json_decode(file_get_contents('php://input'), true);
  22.  
  23. $senderId = $input['entry'][0]['messaging'][0]['sender']['id'];
  24. $messageText = $input['entry'][0]['messaging'][0]['message']['text'];
  25. $response = null;
  26.  
  27. //set Message
  28.  
  29.  
  30. if($messageText == "hi") { $answer = "Hello there! :)";}
  31. if($messageText == "Hi") { $answer = "Hello there! :)";}
  32.  
  33. if($messageText == "amen") {$answer = "Namaste' ";}
  34. if($messageText == "Amen") {$answer = "Namaste' ";}
  35.  
  36.  
  37. if($messageText == "help") {
  38. $answer = "Typing !bookcha:pter (ie; !John3:16 would enable John 3:16 -Thank you!";}
  39.  
  40. if($messageText == "Help") {
  41. $answer = "Typing !bookcha:pter (ie; !John3:16 would enable John 3:16 -Thank you!";}
  42.  
  43. 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.";}
  44.  
  45. 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. :)";}
  46.  
  47. 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. :)";}
  48.  
  49.  
  50. //$rem = "$messengerText . $otherstring";
  51. //if(strpos( "x".$messageText, '!' ) !== false ) ;
  52.  
  53. // Create connection
  54. $conn = new mysqli($servername, $username, $password, $dbname);
  55. // Check connection
  56. if ($conn->connect_error) {
  57. die("Connection failed: " . $conn->connect_error);
  58. }
  59.  
  60. //$messageText = "!Ecc1:1";
  61. list($msgat, $message) = explode("!", $messageText, 2);
  62.  
  63.  
  64. $sql = "SELECT verse FROM ".$datatable." WHERE book LIKE '%".$message."'";
  65.  
  66. $result = $conn->query($sql);
  67.  
  68. if ($result->num_rows > 0) {
  69. // output data of each row
  70. while($row = $result->fetch_assoc()) {
  71.  
  72. //send message to facebook bot
  73. }
  74. if ($msgat == "!")
  75. {
  76. //*// THIS has not been working.
  77. $answer = (" " . $row["verse"]); //this will store value into single variable answer
  78.  
  79. }
  80.  
  81. $response = [
  82.  
  83. 'recipient' => [ 'id' => $senderId ],
  84. 'message' => [ 'text' => $answer ]
  85. ];
  86.  
  87.  
  88. //needed for else? "}"?
  89. }
  90.  
  91. else {
  92.  
  93.  
  94. $response = [
  95.  
  96. 'recipient' => [ 'id' => $senderId ],
  97. 'message' => [ 'text' => $answer ]
  98. ];
  99.  
  100. }
  101.  
  102. $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$accessToken);
  103. curl_setopt($ch, CURLOPT_POST, 1);
  104. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
  105. curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  106. if(!empty($input)){
  107. $result = curl_exec($ch);
  108. }
  109. curl_close($ch);
  110. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement