Example #1
0
 public function testPlayConvienceMethod()
 {
     $r = new Response();
     $r->addPlay("hello-monkey.mp3", array("loop" => 3));
     $expected = '<Response><Play loop="3">hello-monkey.mp3</Play></Response>';
     $this->assertXmlStringEqualsXmlString($expected, $r->asUrl(False));
 }
Example #2
0
<?php

require_once 'lib/plivo.php';
$r = new Response();
$body = 'Hi, Calling from Plivo';
$url = 'http://examples.com/playTrumpet.mp3';
$attributes = array('loop' => 2);
$r->addSpeak($body, $attributes);
$r->addPlay($url, $attributes);
$wait_attribute = array('length' => 3);
$r->addWait($wait_attribute);
header('Content-type: text/xml');
echo $r->toXML();
Example #3
0
        $getDigits->addSpeak($IVR_MESSAGE1);
        $r->addSpeak($NO_INPUT_MESSAGE);
        Header('Content-type: text/xml');
        echo $r->toXML();
        break;
    case "POST":
        $digit = $_REQUEST['Digits'];
        if ($digit == '1') {
            $getdigits_action_url = "https://example.com/phone_tree.php";
            $params = array('action' => $getdigits_action_url, 'method' => 'GET', 'timeout' => '7', 'numDigits' => '1', 'retries' => '1');
            $getDigits = $r->addGetDigits($params);
            $getDigits->addSpeak($IVR_MESSAGE2);
            $r->addSpeak($NO_INPUT_MESSAGE);
        } else {
            if ($digit == '2') {
                $r->addPlay($PLIVO_SONG);
            } else {
                $r->addSpeak($WRONG_INPUT_MESSAGE);
            }
        }
        Header('Content-type: text/xml');
        echo $r->toXML();
        break;
}
?>

<!--phone_tree.php-->

<?php 
require_once "plivo.php";
$WRONG_INPUT_MESSAGE = "Sorry, it's a wrong input.";
Example #4
0
$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/>
   </Response>
<?php

require_once "./plivo.php";
// Generate a Play XML with the details of the audio file to play on the call.
$body = "https://s3.amazonaws.com/plivocloud/Trumpet.mp3";
$r = new Response();
// Add Play element
$r->addPlay($body);
Header('Content-type: text/xml');
echo $r->toXML();
/*
Sample Output
<Response>
    <Play>https://s3.amazonaws.com/plivocloud/Trumpet.mp3</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>
       </GetDigits>
       <Wait length="5"/>
       <Play loop="2">/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-hello.wav</Play>
       <Record/>
       <Hangup/>
   </Response>
   */
// ========================================================================
Example #7
0
<?php

define('IS_DEV', true);
require_once 'twilio.php';
if (IS_DEV) {
    require_once 'twillip.php';
    Twillip::Start();
}
$r = new Response();
if (isset($_REQUEST['Caller'])) {
    $r->addSay('This app uses Twillip for obviously awesome reasons!');
    $r->addPlay('funky-beats.mp3', array('loop' => 3));
    $r->addRedirect('/doesntexist.php');
} else {
    $r->addSay('Oh no! I didn\'t get sent a phone number! Who in blue blazes are you?');
    $r->addSay('This line will generate a PHP warning now: ' . $_REQUEST['Caller']);
}
$r->respond();
if (IS_DEV) {
    Twillip::End();
}
<?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();
$r->addPlay($base_http . "/duck.mp3", array('loop' => 4));
$r->Respond();
Example #9
0
<?php

require_once 'plivo.php';
$response = new Response();
$input_digits = $_REQUEST['Digits'];
if ($input_digits == '1') {
    $response->addPlay($_REQUEST['RecordUrl']);
    $response->addRedirect('http://' . $_SERVER["SERVER_NAME"] . '/plivo-voicemail/confirm-input.php', array('method' => 'GET'));
} else {
    if ($input_digits == '2') {
        $response->addRedirect('http://' . $_SERVER["SERVER_NAME"] . '/plivo-voicemail/get-input.php', array('method' => 'GET'));
    } else {
        if ($input_digits == '3') {
            $response->addSpeak('Your message is saved. Bye.');
            // do necessary actions to save the recording and call uuid mapping.
        } else {
            $response->addSpeak('Invalid input');
            $response->addRedirect('http://' . $_SERVER["SERVER_NAME"] . '/plivo-voicemail/get-input.php', array('method' => 'GET'));
        }
    }
}
header('Content-Type: text/xml');
echo $response->toXML();