SHARE
TWEET

index.php

trupsalms Sep 27th, 2018 7 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. // Facebook Webhooks for Incredible PBX ver. 170928, (c) Copyright 2017, Ward Mundy & Associates LLC. All rights reserved.
  4. // Licensed pursuant to GPL2. See COPYING for GPL2 license terms and conditions.
  5.  
  6. // Configure the phone from which outbound calls will be made by editing .cli-call script.
  7. // Add your credentials in BOTH config.inc.php and cli-message.php
  8.  
  9.  
  10. include_once("config.inc.php");
  11.  
  12. $hub_verify_token = $verify_token ;
  13. $hub_challenge = "" ;
  14.  
  15. if (!empty($_REQUEST['hub_verify_token'])) :
  16.  $hub_verify_token = $_REQUEST['hub_verify_token'];
  17.  $hub_challenge = $_REQUEST['hub_challenge'];
  18.  
  19.  if ( $hub_verify_token == $verify_token ) :
  20.   echo $hub_challenge;
  21.   exit;
  22.  else :
  23.   exit;
  24.  endif;
  25. endif;
  26.  
  27. $input = json_decode(file_get_contents('php://input'), true);
  28. $senderId = $input['entry'][0]['messaging'][0]['sender']['id'];
  29. $messageText = $input['entry'][0]['messaging'][0]['message']['text'];
  30. if ( $messageText == "howdy" ) :
  31.     $answer = "Hi there and welcome to BotWorld. SenderID:  $senderId";
  32.     $response = [
  33.    
  34.         'recipient' => [ 'id' => $senderId ],
  35.         'message' => [ 'text' => $answer ]
  36.     ];
  37.  
  38.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  39.     curl_setopt($ch, CURLOPT_POST, 1);
  40.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
  41.     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  42.     curl_exec($ch);
  43.     curl_close($ch);
  44.  
  45. elseif ( strtolower(substr($messageText,0,4)) == "dial" ) :
  46.  
  47.     $answer = "Placing call to ". substr($messageText,5) . " after connecting with your designated phone...";
  48.     $response = [
  49.    
  50.         'recipient' => [ 'id' => $senderId ],
  51.         'message' => [ 'text' => $answer ]
  52.     ];
  53.  
  54.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  55.     curl_setopt($ch, CURLOPT_POST, 1);
  56.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
  57.     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  58.     curl_exec($ch);
  59.     curl_close($ch);
  60.  
  61.     $num2call = substr($messageText,5);
  62.     shell_exec("./.cli-call $num2call");
  63.  
  64. elseif ( substr($messageText,0,1) == "!" ) :
  65.     $cmd = substr($messageText,1);
  66.     $CLI = shell_exec($cmd);
  67.     $CLI = str_replace(chr(10),"\n",$CLI);
  68.     $CLI = str_replace(chr(13),"\n",$CLI);
  69.     $answer = "$CLI";
  70.     $response = [
  71.    
  72.         'recipient' => [ 'id' => $senderId ],
  73.         'message' => [ 'text' => $answer ]
  74.     ];
  75.  
  76.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  77.     curl_setopt($ch, CURLOPT_POST, 1);
  78.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
  79.     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  80.     curl_exec($ch);
  81.     curl_close($ch);
  82.  
  83. elseif ( substr($messageText,0,1) == "?" ) :
  84.     $answer="";
  85.     var_dump($_REQUEST);
  86.     if (empty($_REQUEST)) :
  87.      $answer="NULL";
  88.     else :
  89.      foreach ($_REQUEST as $name => $value) {
  90.       $answer = $answer."$name = $value\n";
  91.      }
  92.      $answer = $answer."EOF\n";
  93.     endif;
  94.     $response = [
  95.    
  96.         'recipient' => [ 'id' => $senderId ],
  97.         'message' => [ 'text' => $answer ]
  98.     ];
  99.  
  100.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  101.     curl_setopt($ch, CURLOPT_POST, 1);
  102.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
  103.     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  104.     curl_exec($ch);
  105.     curl_close($ch);
  106.  
  107. elseif ( strtolower(substr($messageText,0,6)) == "lookup" or strtolower(substr($messageText,0,4)) == "call" ) :
  108.    if ( strtolower(substr($messageText,0,4)) == "call" ):
  109.     $account = substr($messageText,5) . "%" ;
  110.    else :
  111.     $account = substr($messageText,7) . "%" ;
  112.    endif;
  113.  
  114.     $phone = "unknown";
  115.  
  116.    if (file_exists('/usr/bin/mysql')):
  117.     $dbhost = "localhost";
  118.     $dbpass = "passw0rd";
  119.     $dbuser = "root";
  120.     $dbname = "asteridex";
  121.     $dbconnection = mysql_connect($dbhost, $dbuser, $dbpass);
  122.     mysql_select_db($dbname);
  123.     $query = "SELECT * FROM user1 where name LIKE '$account'";
  124.     $result = mysql_query($query);
  125.     $row = mysql_fetch_array($result);
  126.     $phone =  $row["out"];
  127.     $acctname = $row["name"];
  128.     mysql_close($dbconnection);
  129.    else :
  130.     $db = new SQLite3('/var/lib/asterisk/agi-bin/asteridex.sqlite');
  131.     $query_string="SELECT * FROM user1 where name LIKE '$account'";
  132.     $db->exec($query_string);
  133.     $result = $db->query($query_string);
  134.     $row = $result->fetchArray();
  135.     $acctname = $row["name"];
  136.     $phone =  $row["out"];
  137.     $db->close();
  138.    endif;
  139.    if ( substr($acctname,0,strlen($account)-1) <> substr($account,0,-1) ):
  140.      $msg = substr($account,0,-1) . " not found in AsteriDex. Use dial command if you know the number.";
  141.      $response = [
  142.    
  143.         'recipient' => [ 'id' => $senderId ],
  144.         'message' => [ 'text' => $msg ]
  145.     ];
  146.  
  147.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  148.     curl_setopt($ch, CURLOPT_POST, 1);
  149.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
  150.     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  151.     curl_exec($ch);
  152.     curl_close($ch);
  153.  
  154.    else :
  155.  
  156.   $result = "Click to call $acctname"."...";
  157.   $phone = "dial $phone";
  158.  
  159.   $jsonData = '{
  160.     "recipient":{
  161.      "id":"'.$senderId.'"
  162.      },
  163.     "message":{
  164.      "text":'.json_encode($result).',
  165.      "quick_replies":[
  166.       {
  167.        "content_type":"text",
  168.        "title":'.json_encode($phone).',
  169.        "payload":'.json_encode($phone).'
  170.       }
  171.      ]
  172.     }
  173.   }';
  174.  
  175.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  176.     $jsonDataEncoded = $jsonData;
  177.     curl_setopt($ch, CURLOPT_POST, 1);
  178.     curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
  179.     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  180.     curl_exec($ch);
  181.     curl_close($ch);
  182.  
  183.    endif;
  184.  
  185. elseif ( strtolower(substr($messageText,0,4)) == "help" ) :
  186.  
  187.   $jsonData = '{
  188.     "recipient":{
  189.      "id":"'.$senderId.'"
  190.      },
  191.     "message":{
  192.      "attachment":{
  193.       "type":"template",
  194.        "payload":{
  195.         "template_type":"button",
  196.         "text":"Need more help?",
  197.         "buttons":[
  198.          {
  199.            "type":"phone_number",
  200.            "title":"Talk to Lenny",
  201.            "payload":"+18436060444"
  202.          },
  203.          {
  204.            "type":"web_url",
  205.            "url":"https://pbxinaflash.com/community/forums/",
  206.            "title":"Visit PIAF Forum",
  207.            "webview_height_ratio":"compact"
  208.          },
  209.          {
  210.            "type":"web_url",
  211.            "url":"https://community.asterisk.org/",
  212.            "title":"Visit Asterisk Forum",
  213.            "webview_height_ratio":"compact"
  214.          }
  215.     ]
  216.       }
  217.      }
  218.     }
  219.   }';
  220.  
  221.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  222.     $jsonDataEncoded = $jsonData;
  223.     curl_setopt($ch, CURLOPT_POST, 1);
  224.     curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
  225.     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  226.     curl_exec($ch);
  227.     curl_close($ch);
  228.  
  229. elseif ( strtolower(substr($messageText,0,3)) == "sms" ) :
  230.     $cmd = "./.smssend ".substr($messageText,4);
  231.     $CLI = shell_exec($cmd);
  232.     $CLI = str_replace(chr(10),"\n",$CLI);
  233.     $CLI = str_replace(chr(13),"\n",$CLI);
  234.     $answer = "$CLI";
  235.     $response = [
  236.  
  237.         'recipient' => [ 'id' => $senderId ],
  238.         'message' => [ 'text' => $answer ]
  239.     ];
  240.  
  241.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  242.     curl_setopt($ch, CURLOPT_POST, 1);
  243.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
  244.     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  245.     curl_exec($ch);
  246.     curl_close($ch);
  247.  
  248. elseif ( strtolower(substr($messageText,0,6)) == "update" ) :
  249.     $cmd = "./.update";
  250.     $CLI = shell_exec($cmd);
  251.     $CLI = str_replace(chr(10),"\n",$CLI);
  252.     $CLI = str_replace(chr(13),"\n",$CLI);
  253.     $answer = "$CLI";
  254.     $response = [
  255.  
  256.         'recipient' => [ 'id' => $senderId ],
  257.         'message' => [ 'text' => $answer ]
  258.     ];
  259.  
  260.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  261.     curl_setopt($ch, CURLOPT_POST, 1);
  262.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
  263.     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  264.     curl_exec($ch);
  265.     curl_close($ch);
  266.  
  267. else :
  268.  
  269.     $answer = $messageText ;
  270.     $response = [
  271.    
  272.         'recipient' => [ 'id' => $senderId ],
  273.         'message' => [ 'text' => $answer ]
  274.     ];
  275.  
  276.     $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
  277.     curl_setopt($ch, CURLOPT_POST, 1);
  278.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
  279.     curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  280.     curl_exec($ch);
  281.     curl_close($ch);
  282.  
  283.  
  284. endif;
  285. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top