public function testSpeakConvienceMethod() { $r = new Response(); $r->addSpeak("Hello Monkey", array("language" => "fr")); $expected = '<Response><Speak language="fr">Hello Monkey</Speak></Response>'; $this->assertXmlStringEqualsXmlString($expected, $r->asUrl(False)); }
<?php require_once "./plivo.php"; $from_number = $_REQUEST['From']; $callers = array('1111111111' => 'ABCDEF', '2222222222' => 'VWXYZ', '3333333333' => 'QWERTY'); $r = new Response(); if (array_key_exists($from_number, $caller)) { $body = "Hello {$caller[$from_number]}"; $r->addSpeak($body); } else { $body = "Hello Stranger!"; $r->addSpeak($body); } Header('Content-type: text/xml'); echo $r->toXML(); /* Sample Output <Response> <Speak>Hello,ABCDEF</Speak> </Response> */
<?php require_once "./plivo.php"; // Generate a Speak XML with the details of the text to play on the call. $body = 'Hi, Calling from Plivo'; $attributes = array('loop' => 2); $r = new Response(); // Add speak element $r->addSpeak($body, $attributes); Header('Content-type: text/xml'); echo $r->toXML(); /* Sample Output <Response> <Speak loop="2">Hi, Calling from Plivo</Speak> </Response> */
<?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->addSpeak('Hello world'); $r->addSpeak('${strepoch()}', array('loop' => 1, 'type' => "CURRENT_DATE_TIME", 'method' => "PRONOUNCED")); $r->addSpeak('${strepoch()}', array('loop' => 5, 'type' => "CURRENT_TIME", 'method' => "PRONOUNCED")); $r->Respond();
<?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();
<?php require_once "./plivo.php"; # Generates a Conference XML $r = new Response(); $params = array('enterSound' => "beep:1", 'callbackUrl' => "https://example.com/conf_callback.php", 'callbackMethod' => "GET"); $name = "demo"; $r->addSpeak("You will now be placed into a demo conference. This is brought to you by Plivo. To know more visit us at plivo.com"); $r->addConference($name, $params); Header('Content-type: text/xml'); echo $r->toXML(); ?> <!--conf_callback.php--> <?php require_once "./plivo.php"; # Record API is called in the callback URL to record the conference $conf_name = $_REQUEST['ConferenceName']; $event = $_REQUEST['Event']; print "Conference Name : {$conf_name}"; print "Event : {$event}"; # The recording starts when the user enters the conference room if ($event == "ConferenceEnter") { $auth_id = "Your AUTH_ID"; $auth_token = "Your AUTH_TOKEN"; $p = new RestAPI($auth_id, $auth_token); $params = array('conference_name' => $conf_name); $resp = $p->record_conference($params); print "URL : {$resp['response']['url']}"; print "Recording ID : {$resp['response']['recording_id']}";
echo $r->toXML(); break; } ?> <!--phone_tree.php--> <?php require_once "plivo.php"; $WRONG_INPUT_MESSAGE = "Sorry, it's a wrong input."; $r = new Response(); $digit = $_REQUEST['Digits']; if ($digit == '1') { $body = "This message is being read out in English"; $params = array('language' => "en-GB"); $r->addSpeak($body, $params); } else { if ($digit == '2') { $body = "Ce message est lu en français"; $params = array('language' => "fr-FR"); $r->addSpeak($body, $params); } else { if ($digit == '3') { $body = "Это сообщение было прочитано в России"; $params = array('language' => "ru-RU"); $r->addSpeak($body, $params); } else { $r->addSpeak($WRONG_INPUT_MESSAGE); } } }
<?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 ($_GET['redirect'] == 'true' || $_POST['redirect'] == 'true') { $r->addSpeak("Redirect done !"); $r->addHangup(); } else { $r->addRedirect($base_http . "/answered.php?redirect=true"); } $r->Respond();
<?php require_once "./plivo.php"; # Generate a Record XML and ask the caller to leave a message $r = new Response(); # The recorded file will be sent to the 'action' URL $record_params = array('action' => 'https://example.com/record_action.php', 'method' => 'GET', 'maxLength' => '30', 'transcriptionType' => 'auto', 'transcriptionUrl' => 'https://example.com/transcription.php', 'transcriptionMethod' => 'GET'); $r->addSpeak("Leave your message after the tone"); $r->addRecord($record_params); Header('Content-type: text/xml'); echo $r->toXML(); ?> <!--record_action.php--> <?php # Action URL Example $record_url = $_REQUEST['RecordUrl']; $record_duration = $_REQUEST['RecordingDuration']; $record_id = $_REQUEST['RecordingID']; echo "Record URL : {$record_url}"; echo "Recording Duration : {$record_duration}"; echo "Recording ID : {$record_id}"; ?> <!--transcription.php--> <?php # Transcription URL Example $transcription = $_REQUEST['transcription']; echo "Transcription is : {$transcription} ";
<?php require_once 'plivo-voicemail/plivo.php'; $r = new Response(); /*Input digits can be processed on the action url*/ $g = $r->addGetDigits(array('action' => 'http://server.com/receive_input.php', 'method' => 'GET')); $g->addSpeak('Press 1 for your message'); $r->addSpeak('Input not received'); header('Content-Type: text/xml'); echo $r->toXML();
<?php require_once 'plivo.php'; $body = 'Hi, Calling from Plivo. Please enter 1 for music and 2 for Speak.'; // $url = 'http://examples.com/playTrumpet.mp3'; $attributes = array('loop' => 2); $getdigitattributes = array('action' => 'http://' . $_SERVER["SERVER_NAME"] . '/gather'); // This is the url where 'Digits' parameter would be sent after user's digit press event $r = new Response(); $g = $r->addGetDigits($getdigitattributes); $g->addSpeak($body, $attributes); $r->addSpeak("Input not recieved", array('language' => 'en-US', 'voice' => 'WOMAN')); echo $r->toXML();
$g->append(new Number("4155551212")); $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();
<?php require_once 'plivo.php'; $response = new Response(); $response->addSpeak('Record your message at the tone, after you are done, press pound'); $response->addRecord(array('action' => 'http://' . $_SERVER["SERVER_NAME"] . '/plivo-voicemail/confirm-input.php', 'method' => 'GET', 'maxLength' => '60', 'finishOnKey' => '#', 'playBeep' => 'true')); $response->addSpeak('Recording not received'); $response->addRedirect('http://' . $_SERVER["SERVER_NAME"] . '/plivo-voicemail/get-input.php', array('method' => 'GET')); header('content-type: text/xml'); echo $response->toXML();
<?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();
<?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['Digits'])) { $digits = $_POST['Digits']; if ($digits != "") { $r->addSpeak("Get Digits. Digits pressed " . $digits); } else { $r->addSpeak("Get Digits. No digits pressed"); } } else { $d = $r->addGetDigits(array("action" => $base_http . "/answered.php", "timeout" => 10, "retries" => 2, "finishOnKey" => "#", "numDigits" => 2, "playBeep" => "true", "validDigits" => "01234")); $d->addSpeak("Get Digits. Press 0, 1, 2, 3 or 4"); } $r->Respond();
<?php require_once "./plivo.php"; // Generate a Speak XML with the details of the text to play on the call. $body = 'This is English!'; $params = array('language' => "en-GB", 'voice' => "MAN"); $r = new Response(); // Add speak element $r->addSpeak($body, $params); $body1 = 'Ce texte généré aléatoirement peut-être utilisé dans vos maquettes'; $params1 = array('language' => "fr-FR"); $r->addSpeak($body1, $params1); $body2 = 'Это случайно сгенерированный текст может быть использован в макете'; $params2 = array('language' => "ru-RU", 'voice' => "MAN"); Header('Content-type: text/xml'); echo $r->toXML(); /* Sample Output <Response> <Speak language="en-GB" voice="MAN">This is English!</Speak> <Speak language="fr-FR"> Ce texte généré aléatoirement peut-être utilisé dans vos maquettes </Speak> <Speak language="ru-RU" voice="MAN"> Это случайно сгенерированный текст может быть использован в макете </Speak> </Response> */