Example #1
0
 public function callSay($text)
 {
     $twiml = new Response();
     //generate url to the selected flow
     $twiml->addSay($text);
     $twiml->addPause(array('length' => 60 * 4));
     $twiml->addHangup();
     $this->startClientCall($twiml);
 }
<?php

header("Content-type: text/xml\n");
error_reporting(E_NONE);
include "chirbit.php";
$user = AppletInstance::getUserGroupPickerValue('chirbit-controller');
$user_id = $user->values["id"];
$chirbit_username = PluginStore::get("chirbit_username_{$user_id}", "");
$chirbit_password = PluginStore::get("chirbit_password_{$user_id}", "");
$prompt = AppletInstance::getAudioSpeechPickerValue('prompt');
$after = AppletInstance::getAudioSpeechPickerValue('after');
$title = AppletInstance::getValue("title", "");
$response = new Response();
if (isset($_REQUEST['RecordingUrl'])) {
    chirbit_post($chirbit_username, $chirbit_password, $_REQUEST['RecordingUrl'], $title);
    $verb = AudioSpeechPickerWidget::getVerbForValue($after, null);
    $response->append($verb);
    $response->addHangup();
} else {
    $verb = AudioSpeechPickerWidget::getVerbForValue($prompt, null);
    $response->append($verb);
    $response->addRecord();
}
$response->Respond();
         } else {
             if ($_REQUEST['data'] == '2') {
                 $_SESSION['next_goto'] = 'DialMenu';
             } else {
                 if ($_REQUEST['data'] == '3') {
                     $_SESSION['next_goto'] = 'Dial1_Status';
                 } else {
                     $r->addPlayText('Thats an invalid input');
                 }
             }
         }
     }
 } else {
     if ($_SESSION['next_goto'] == 'DialMenu') {
         $r->addPlayText('Place Details');
         $r->addHangup();
     } 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('Going back to main menu');
             $url = "https://www.google.com/speech-api/v2/recognize?output=json&lang=en_US&key=AIzaSyA89KWhdKtIWJ38pz8CuK5HDgiB4Uum3Ak";
             $data = file_get_contents($_SESSION['record_url']);
             $r = POST($url, $data);
             $results = explode("\n", $r);
             foreach ($results as $result) {
                 $object = json_decode($result, true);
                 if (isset($object['result']) == true && count($object['result']) > 0) {
$r = new Response();
if ($dst) {
    $dial_params = array();
    if ($src) {
        $dial_params['callerId'] = $src;
    }
    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);
        }
    }
<?php

require_once "./plivo.php";
$r = new Response();
// Generate a Hangup XML
$params = array('reason' => 'busy', 'schedule' => '60');
$body = "This call will be hung up in 1 minute";
$r->addSpeak($body);
$r->addHangup($params);
Header('Content-type: text/xml');
echo $r->toXML();
/*
Sample Output
<Response>
   <Speak>This call will be hung up in 1 minute</Speak>
   <Hangup reason="busy" schedule="60" />
</Response>
*/
Example #6
0
 public function testHangupConvience()
 {
     $r = new Response();
     $r->addHangup();
     $expected = '<Response><Hangup></Hangup></Response>';
     $this->assertXmlStringEqualsXmlString($expected, $r->asUrl(False));
 }
Example #7
0
<?php

require_once 'plivo.php';
$attributes = array('reason' => "busy");
$r = new Response();
// Add hangup element
$r->addHangup($attributes);
echo $r->toXML();
/* 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:
   <Response>
       <GetDigits numdigits="1">
           <Play loop="2">/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-hello.wav</Play>