Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Facebook Webhooks for Incredible PBX ver. 170928, (c) Copyright 2017, Ward Mundy & Associates LLC. All rights reserved.
- // Licensed pursuant to GPL2. See COPYING for GPL2 license terms and conditions.
- // Configure the phone from which outbound calls will be made by editing .cli-call script.
- // Add your credentials in BOTH config.inc.php and cli-message.php
- include_once("config.inc.php");
- $hub_verify_token = $verify_token ;
- $hub_challenge = "" ;
- if (!empty($_REQUEST['hub_verify_token'])) :
- $hub_verify_token = $_REQUEST['hub_verify_token'];
- $hub_challenge = $_REQUEST['hub_challenge'];
- if ( $hub_verify_token == $verify_token ) :
- echo $hub_challenge;
- exit;
- else :
- exit;
- endif;
- endif;
- $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'];
- if ( $messageText == "howdy" ) :
- $answer = "Hi there and welcome to BotWorld. SenderID: $senderId";
- $response = [
- 'recipient' => [ 'id' => $senderId ],
- 'message' => [ 'text' => $answer ]
- ];
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
- curl_exec($ch);
- curl_close($ch);
- elseif ( strtolower(substr($messageText,0,4)) == "dial" ) :
- $answer = "Placing call to ". substr($messageText,5) . " after connecting with your designated phone...";
- $response = [
- 'recipient' => [ 'id' => $senderId ],
- 'message' => [ 'text' => $answer ]
- ];
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
- curl_exec($ch);
- curl_close($ch);
- $num2call = substr($messageText,5);
- shell_exec("./.cli-call $num2call");
- elseif ( substr($messageText,0,1) == "!" ) :
- $cmd = substr($messageText,1);
- $CLI = shell_exec($cmd);
- $CLI = str_replace(chr(10),"\n",$CLI);
- $CLI = str_replace(chr(13),"\n",$CLI);
- $answer = "$CLI";
- $response = [
- 'recipient' => [ 'id' => $senderId ],
- 'message' => [ 'text' => $answer ]
- ];
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
- curl_exec($ch);
- curl_close($ch);
- elseif ( substr($messageText,0,1) == "?" ) :
- $answer="";
- var_dump($_REQUEST);
- if (empty($_REQUEST)) :
- $answer="NULL";
- else :
- foreach ($_REQUEST as $name => $value) {
- $answer = $answer."$name = $value\n";
- }
- $answer = $answer."EOF\n";
- endif;
- $response = [
- 'recipient' => [ 'id' => $senderId ],
- 'message' => [ 'text' => $answer ]
- ];
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
- curl_exec($ch);
- curl_close($ch);
- elseif ( strtolower(substr($messageText,0,6)) == "lookup" or strtolower(substr($messageText,0,4)) == "call" ) :
- if ( strtolower(substr($messageText,0,4)) == "call" ):
- $account = substr($messageText,5) . "%" ;
- else :
- $account = substr($messageText,7) . "%" ;
- endif;
- $phone = "unknown";
- if (file_exists('/usr/bin/mysql')):
- $dbhost = "localhost";
- $dbpass = "passw0rd";
- $dbuser = "root";
- $dbname = "asteridex";
- $dbconnection = mysql_connect($dbhost, $dbuser, $dbpass);
- mysql_select_db($dbname);
- $query = "SELECT * FROM user1 where name LIKE '$account'";
- $result = mysql_query($query);
- $row = mysql_fetch_array($result);
- $phone = $row["out"];
- $acctname = $row["name"];
- mysql_close($dbconnection);
- else :
- $db = new SQLite3('/var/lib/asterisk/agi-bin/asteridex.sqlite');
- $query_string="SELECT * FROM user1 where name LIKE '$account'";
- $db->exec($query_string);
- $result = $db->query($query_string);
- $row = $result->fetchArray();
- $acctname = $row["name"];
- $phone = $row["out"];
- $db->close();
- endif;
- if ( substr($acctname,0,strlen($account)-1) <> substr($account,0,-1) ):
- $msg = substr($account,0,-1) . " not found in AsteriDex. Use dial command if you know the number.";
- $response = [
- 'recipient' => [ 'id' => $senderId ],
- 'message' => [ 'text' => $msg ]
- ];
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
- curl_exec($ch);
- curl_close($ch);
- else :
- $result = "Click to call $acctname"."...";
- $phone = "dial $phone";
- $jsonData = '{
- "recipient":{
- "id":"'.$senderId.'"
- },
- "message":{
- "text":'.json_encode($result).',
- "quick_replies":[
- {
- "content_type":"text",
- "title":'.json_encode($phone).',
- "payload":'.json_encode($phone).'
- }
- ]
- }
- }';
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- $jsonDataEncoded = $jsonData;
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
- curl_exec($ch);
- curl_close($ch);
- endif;
- elseif ( strtolower(substr($messageText,0,4)) == "help" ) :
- $jsonData = '{
- "recipient":{
- "id":"'.$senderId.'"
- },
- "message":{
- "attachment":{
- "type":"template",
- "payload":{
- "template_type":"button",
- "text":"Need more help?",
- "buttons":[
- {
- "type":"phone_number",
- "title":"Talk to Lenny",
- "payload":"+18436060444"
- },
- {
- "type":"web_url",
- "url":"https://pbxinaflash.com/community/forums/",
- "title":"Visit PIAF Forum",
- "webview_height_ratio":"compact"
- },
- {
- "type":"web_url",
- "url":"https://community.asterisk.org/",
- "title":"Visit Asterisk Forum",
- "webview_height_ratio":"compact"
- }
- ]
- }
- }
- }
- }';
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- $jsonDataEncoded = $jsonData;
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
- curl_exec($ch);
- curl_close($ch);
- elseif ( strtolower(substr($messageText,0,3)) == "sms" ) :
- $cmd = "./.smssend ".substr($messageText,4);
- $CLI = shell_exec($cmd);
- $CLI = str_replace(chr(10),"\n",$CLI);
- $CLI = str_replace(chr(13),"\n",$CLI);
- $answer = "$CLI";
- $response = [
- 'recipient' => [ 'id' => $senderId ],
- 'message' => [ 'text' => $answer ]
- ];
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
- curl_exec($ch);
- curl_close($ch);
- elseif ( strtolower(substr($messageText,0,6)) == "update" ) :
- $cmd = "./.update";
- $CLI = shell_exec($cmd);
- $CLI = str_replace(chr(10),"\n",$CLI);
- $CLI = str_replace(chr(13),"\n",$CLI);
- $answer = "$CLI";
- $response = [
- 'recipient' => [ 'id' => $senderId ],
- 'message' => [ 'text' => $answer ]
- ];
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
- curl_exec($ch);
- curl_close($ch);
- else :
- $answer = $messageText ;
- $response = [
- 'recipient' => [ 'id' => $senderId ],
- 'message' => [ 'text' => $answer ]
- ];
- $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
- curl_exec($ch);
- curl_close($ch);
- endif;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement