function initcall() { if ($_REQUEST["CallStatus"] == "completed") { // receives request from Twilio server when a call ends // remove call from active calls // saves call info in DB as current call $callGuid = $_REQUEST["CallGuid"]; $db = new PDO("sqlite:twilio.db"); $query = "UPDATE Calls SET Status = 'ended' WHERE CallGuid = '{$callGuid}'"; $db->exec($query); } else { // dial all saved numbers for your account $numbers = getNumbersToCall(); // get numbers $r = new Response(); for ($i = 0; $i < count($numbers); $i++) { $r->addDial($numbers[$i]); } $r->Respond(); // saves call info in DB as current call $callGuid = $_REQUEST["CallGuid"]; $caller = $_REQUEST["Caller"]; $callLocation = $_REQUEST["CallerCity"] != "" ? $_REQUEST["CallerCity"] : ($_REQUEST["CallerState"] != "" ? $_REQUEST["CallerState"] : ($_REQUEST["CallerZip"] != "" ? $_REQUEST["CallerZip"] : ($_REQUEST["CallerCountry"] != "" ? $_REQUEST["CallerCountry"] : ""))); $db = new PDO("sqlite:twilio.db"); $query = "INSERT INTO Calls (CallGuid, Caller, Location, Status) VALUES ('{$callGuid}', '{$caller}', '{$callLocation}', 'active')"; $db->exec($query); } }
function connect($number, $ext) { header('X-WP-Click2Call: ' . WP_CLICK2CALL_VERSION); $twilio = new Response(); $greeting = get_option('wpc2c_custom_greeting'); if (!empty($greeting)) { $twilio->addSay($greeting); } $dial = $twilio->addDial(); $dial_options = array(); if (!empty($ext)) { $dial_options = array('sendDigits' => $ext); } $dial->addNumber($number, $dial_options); $twilio->Respond(); }
<?php require_once "./plivo.php"; // Feth the from_number from the URL $from_numbr = $_REQUEST['From']; $r = new Response(); // Add Dial tag $params = array('callerId' => $from_numbr); $d = $r->addDial($params); $number = "2222222222"; $d->addNumber($number); Header('Content-type: text/xml'); echo $r->toXML(); /* Sample Output <Response> <Dial callerId="1111111111"> <Number>2222222222</Number> </Dial> </Response> */
default: break; } } // This loop exists only so that we can quickly make state transitions by // setting a new DIAL_ACTION and jumping to the top of the loop. $keepLooping = true; while ($keepLooping) { // By default we'll only go once through the loop. $keepLooping = false; switch ($state[DIAL_ACTION]) { case DIAL_STATE_DIAL: error_log('numbers left to try'); if ($state[DIAL_NUMBER_INDEX] < count($numbers)) { // There are still more numbers left to try $dial = $response->addDial(array('action' => current_url())); if ($dial_whom_selector === 'user-or-group') { $name = null; if ($dial_whom_user_or_group instanceof VBX_User) { $name = $dial_whom_user_or_group->first_name . " " . $dial_whom_user_or_group->last_name; } else { if ($dial_whom_user_or_group instanceof VBX_Group) { $name = $dial_whom_user_or_group->name; } else { // In practice, this should never ever happen. $name = "Unknown"; } } $dial->addNumber($numbers[$state[DIAL_NUMBER_INDEX]], array('url' => site_url('twiml/whisper?name=' . urlencode($name)))); } else { // If we're just dialing an arbitrary number, we don't announce anything about
} } // This loop exists only so that we can quickly make state transitions by // setting a new DIAL_ACTION and jumping to the top of the loop. $keepLooping = true; while ($keepLooping) { // By default we'll only go once through the loop. $keepLooping = false; error_log(var_export($state, true)); error_log($state[DIAL_ACTION]); switch ($state[DIAL_ACTION]) { case DIAL_STATE_DIAL: error_log('numbers left to try'); if ($state[DIAL_NUMBER_INDEX] < count($numbers)) { // There are still more numbers left to try $dial = $response->addDial(); if ($dial_whom_selector === 'user-or-group') { $name = null; if ($dial_whom_user_or_group instanceof VBX_User) { $name = $dial_whom_user_or_group->first_name . " " . $dial_whom_user_or_group->last_name; } else { if ($dial_whom_user_or_group instanceof VBX_Group) { $name = $dial_whom_user_or_group->name; } else { // In practice, this should never ever happen. $name = "Unknown"; } } $dial->addNumber($numbers[$state[DIAL_NUMBER_INDEX]], array('url' => site_url('twiml/whisper?name=' . urlencode($name)))); } else { // If we're just dialing an arbitrary number, we don't announce anything about
} if ($cname) { $dial_params['callerName'] = $cname; } if (substr($dst, 0, 4) == "sip:") { $is_sip_user = TRUE; } else { $is_sip_user = FALSE; } if ($is_sip_user and in_array($disable_call, array("all", "sip"))) { $r->addHangup(array("reason" => "busy")); } elseif (!$is_sip_user and in_array($disable_call, array("all", "number"))) { $r->addHangup(array("reason" => "busy")); } else { if ($dial_music) { $dial_params["dialMusic"] = $dial_music; $d = $r->addDial($dial_params); } else { $d = $r->addDial($dial_params); } if ($is_sip_user) { $d->addUser($dst); } else { $d->addNumber($dst); } } } else { $r->addHangup(); } header("Content-Type: text/xml"); echo $r->toXML();
<?php require 'plivo.php'; $dst = $_REQUEST['To']; $src = $_REQUEST['CLID']; if (!$src) { $src = $_REQUEST['From']; } $cname = $_REQUEST['CallerName']; $response = new Response(); if ($dst) { $dial_params = array(); if ($src) { $dial_params['callerId'] = $src; } if ($cname) { $dial_params['callerName'] = $cname; } $dial = $response->addDial($dial_params); if (substr($dst, 0, 4) == "sip:") { $dial->addUser($dst); } else { $dial->addNumber($dst); } } else { $response->addHangup(); } header("Content-Type: text/xml"); echo $response->toXML();
<?php require_once 'plivo.php'; $r = new Response(); $d = $r->addDial(array("callerId" => "2XXXXXXX")); $d->addNumber('1XXXXXXX'); echo $r->toXML(); // Output: // <Response> // <Dial callerId="2XXXXXXX"> // <Number>1XXXXXXX</Number> // </Dial> // </Response> ?>
public function testDialConvience() { $r = new Response(); $r->addDial(); $expected = '<Response><Dial></Dial></Response>'; $this->assertXmlStringEqualsXmlString($expected, $r->asUrl(False)); }
<?php // Include the PHP Plivo Rest library require "./plivohelper.php"; $base_http = "http://" . dirname($_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"]); /* Render RESTXML */ $r = new Response(); if (isset($_POST['HangupCause']) && isset($_POST['RingStatus'])) { $hangup_cause = $_POST['HangupCause']; $ring_status = $_POST['RingStatus']; $r->addSpeak("Dial Hangup Cause is " . $hangup_cause); $r->addSpeak("Dial Ring Status is " . $ring_status); $r->addSpeak("Dial Ended"); } else { $r->addSpeak("Dial Test"); $d = $r->addDial(array('action' => $base_http . "/answered.php", 'timeLimit' => 60, 'hangupOnStar' => 'true')); $d->addNumber("4871", array('gateways' => "sofia/gateway/pstn", 'gatewayTimeouts' => 30)); $d->addNumber("1749", array('gateways' => "sofia/gateway/pstn", 'gatewayTimeouts' => 30)); } $r->Respond();
function connect($number) { $twilio = new Response(); $twilio->addDial($number); $twilio->Respond(); }
$r = new Response(); $r->append(new Say("Hello World", array("voice" => "man", "language" => "fr", "loop" => "10"))); $r->append(new Dial("4155551212", array("timeLimit" => "45"))); $r->append(new Play("http://www.mp3.com")); $r->Respond(); /* outputs: <Response> <Say voice="man" language="fr" loop="10">Hello World</Say> <Play>http://www.mp3.com</Play> <Dial timeLimit="45">4155551212</Dial> </Response> */ // The same XML can be created above using the convencience methods $r = new Response(); $r->addSay("Hello World", array("voice" => "man", "language" => "fr", "loop" => "10")); $r->addDial("4155551212", array("timeLimit" => "45")); $r->addPlay("http://www.mp3.com"); //$r->Respond(); // ======================================================================== // Gather, Redirect $r = new Response(); $g = $r->append(new Gather(array("numDigits" => "1"))); $g->append(new Say("Press 1")); $r->append(new Redirect()); //$r->Respond(); /* outputs: <Response> <Gather numDigits="1"> <Say>Press 1</Say> </Gather> <Redirect/>
$r->addRedirect($redirect); Header('Content-type: text/xml'); echo $r->toXML(); ?> <!--connect.php--> <?php require_once "./plivo.php"; $r = new Response(); // Add Speak tag $body = "Connecting your call.."; $attributes = array('action' => "https://example.com/dial_status.php", 'method' => "GET", 'redirect' => "true"); $r->addSpeak($body); // Add Dial tag $d = $r->addDial($attributes); $number = "11111111111"; $d->addNumber($number); Header('Content-type: text/xml'); echo $r->toXML(); /* Sample Output <Response> <Speak>Please wait while your call is being transferred</Speak> <Redirect> https://glacial-harbor-8656.herokuapp.com/testing.php/connect </Redirect> </Response> <Response> <Speak>Connecting your call..</Speak>
$collectInput->setTermChar('#'); $r->addCollectDtmf($collectInput); $_SESSION['next_goto'] = 'Menu1_CheckInput1'; } else { if ($_REQUEST['event'] == 'GotDTMF' && $_SESSION['next_goto'] == 'Menu1_CheckInput1') { //input will come in data param //print print parameter data value if ($_REQUEST['data'] == '') { //if value null, caller has not given any dtmf //no input handled $r->addPlayText('you have not entered any input'); $_SESSION['next_goto'] = 'Menu1'; } else { $_SESSION['dial'] = $_REQUEST['data']; $r->addPlayText('please wait while we transfer your call to our customer care'); $r->addDial($_SESSION['dial'], 'true', 1000, 30, 'ring'); $_SESSION['next_goto'] = 'Dial1_Status'; } } else { if ($_REQUEST['event'] == 'Record' && $_SESSION['next_goto'] == 'Record_Status') { //recorded file will be come as url in data param //print parameter data value $r->addPlayText('your recorded audio is '); $_SESSION['record_url'] = $_REQUEST['data']; $r->addPlayAudio($_SESSION['record_url']); $r->addPlayText('Thanks you for calling, have a nice day'); $r->addHangup(); } else { if ($_REQUEST['event'] == 'Dial' && $_SESSION['next_goto'] == 'Dial1_Status') { //dial url will come data param //if dial record false then data value will be -1 or null //dial status will come in status (answered/not_answered) param
<?php require_once "./plivo.php"; // Add Speak tag $body = 'Connecting your call..'; $r = new Response(); // Add speak element $r->addSpeak($body); // Add Dial tag $number = "2222222222"; $d = $r->addDial(); $d->addNumber($number); Header('Content-type: text/xml'); echo $r->toXML(); /* Sample Output <Response> <Speak>Connecting your call..</Speak> <Dial> <Number>2222222222</Number> </Dial> </Response> */
$r->append($g); $r->append(new Play("http://www.mp3.com")); $r->Respond(); /* outputs: <Response> <Speak loop="10">Hello World</Speak> <Dial timeLimit="45"> <Number>4155551212</Number> </Dial> <Play>http://www.mp3.com</Play> </Response> */ // The same XML can be created above using the convencience methods $r = new Response(); $r->addSpeak("Hello World", array("loop" => "10")); $g = $r->addDial(array("timeLimit" => "45")); $g->addNumber("4155551212"); $r->addPlay("http://www.mp3.com"); $r->addHangup(array("schedule" => "45")); $r->Respond(); // ======================================================================== // GetDigits, Redirect $r = new Response(); $g = $r->addgetDigits(array("numDigits" => "1", "timeout" => "25", "playBeep" => "true")); $g->addPlay("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-hello.wav", array("loop" => "10")); $r->addWait(array("length" => "5")); $r->addPlay("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-hello.wav", array("loop" => "10")); $r->addRecord(array("bothLegs" => "true")); $r->addredirect(); $r->Respond(); /* outputs: