$from = "+254711082300"; // Specify the numbers to call - Query random user, make call, record the conversation $callQuery = "SELECT * FROM users WHERE `phoneNumber`!= '" . $phoneNumber . "' ORDER BY RAND() LIMIT 1"; $callResult = $db->query($callQuery); $callAvail = $callResult->fetch_assoc(); print_r($callAvail); $callOut = $callAvail['phoneNumber']; //Call Random User $to = $callOut; // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway($username, $apikey); // Any gateway errors will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { // Make the call $gateway->call($from, $to); echo "Calls have been initiated. Time for song and dance!\n"; // Our API will now contact your callback URL once the recipient answers the call! } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while making the call: " . $e->getMessage(); } } elseif ($userResponse == "3") { $response = "END Please wait while we load your account.\n"; // Search DB and the Send Airtime $recipients = array(array("phoneNumber" => "" . $phoneNumber . "", "amount" => "KES 10")); //JSON encode $recipientStringFormat = json_encode($recipients); //Create an instance of our awesome gateway class and pass your credentials $gateway = new AfricasTalkingGateway($username, $apiKey); // Thats it, hit send and we'll take care of the rest. Any errors will be captured in the Exception class as shown below try {
$direction = $_POST['direction']; $sessionID = $_POST['sessionId']; $isCallActive = $_POST['isActive']; if ($isCallActive == 1 && $direction == "Inbound") { //hang up //construct response $response = '<?xml version="1.0" encoding="UTF-8"?>'; $response .= '<Response>'; $response .= '<Reject/>'; $response .= '</Response>'; header('Content-type: text/plain'); echo $response; //immediately call user back $gateway = new AfricasTalkingGateway($aitusername, $aitkey); try { $gateway->call($aitnumber, $callerNumber); } catch (Exception $e) { echo "error: " . $e->getMessage(); } } elseif ($isCallActive == 1 && $direction == "Outbound") { //redirect call to be processed on other page $url = "https://santa-slybard.c9users.io/wishlist.php"; //construct response $response = '<?xml version="1.0" encoding="UTF-8"?>'; $response .= '<Response>'; $response .= '<Redirect>' . $url . '</Redirect>'; $response .= '</Response>'; header('Content-type: text/plain'); echo $response; } else { SendResponse(false, "Goodbye!");