Esempio n. 1
0
echo $r->toXML();
/* 
Sample Wait XML
<Response>
    <Wait length="10" />
    <Speak>Hello</Speak>
</Response>
*/
?>

<!-- Beep detetion -->

<?php 
require 'vendor/autoload.php';
use Plivo\Response;
$r = new Response();
// Add Wait tag
$params = array('length' => '10', 'beep' => 'true');
$r->addWait($params);
// Add Speak tag
$body = "Hello";
$r->addSpeak($body);
Header('Content-type: text/xml');
echo $r->toXML();
/*
Sample Wait XML
<Response>
    <Wait length="10" beep="true" />
    <Speak>Hello</Speak>
</Response>
*/
<?php

require 'vendor/autoload.php';
use Plivo\Response;
$from_number = $_REQUEST['From'];
$callers = array('1111111111' => 'ABCDEF', '2222222222' => 'VWXYZ', '3333333333' => 'QWERTY');
$r = new Response();
if (array_key_exists($from_number, $callers)) {
    $body = "Hello {$callers[$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 'vendor/autoload.php';
use Plivo\Response;
$r = new Response();
$body = "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->addSpeak($body);
$params = array('enterSound' => "beep:2", 'record' => "true", 'action' => "https://example.com/conf_action.php", 'method' => "GET", 'record' => "true", 'callbackUrl' => "https://example.com/conf_callback.php", 'callbackMethod' => "GET", 'startConferenceOnEnter' => "true", 'endConferenceOnExit' => "true");
$conference_name = "demo";
$r->addConference($conference_name, $params);
Header('Content-type: text/xml');
echo $r->toXML();
?>

<!--conf_action.php-->

<?php 
$conf_name = $_REQUEST['ConferenceName'];
$conf_uuid = $_REQUEST['ConferenceUUID'];
$conf_mem_id = $_REQUEST['ConferenceMemberID'];
$record_url = $_REQUEST['RecordUrl'];
$record_id = $_REQUEST['RecordingID'];
error_log("Conference Name : {$conf_name}, Conference UUID : conf_uuid, Conference Member ID : conf_mem_id, Record URL : {$record_url}, Record ID : {$record_id}");
echo "Conference Name : {$conf_name}, Conference UUID : conf_uuid, Conference Member ID : conf_mem_id, Record URL : {$record_url}, Record ID : {$record_id}";
?>

<!--conf_callback.php-->

<?php 
$conf_action = $_REQUEST['ConferenceAction'];
$conf_name = $_REQUEST['ConferenceName'];
$r = new Response();
$params = array('dialMusic' => 'https://example.com/custom_tone.php');
// Add Dial tag
$d = $r->addDial($params);
$number = "1111111111";
$d->addNumber($number);
Header('Content-type: text/xml');
echo $r->toXML();
?>

<!--custom_tone.php-->

<?php 
require 'vendor/autoload.php';
use Plivo\Response;
$r = new Response();
$body = "https://s3.amazonaws.com/plivocloud/music.mp3";
// Add Play tag
$r->addPlay($body);
Header('Content-type: text/xml');
echo $r->toXML();
/*
Sample Output
<Response>
    <Dial dialMusic="https://glacial-harbor-8656.herokuapp.com/testing.php/custom_tone">
        <Number>1111111111</Number>
    </Dial>
</Response>

<Response>
    <Play>https://s3.amazonaws.com/plivocloud/music.mp3</Play>
//Add Speak tag
$body = "Please wait while your call is being transferred";
$r->addSpeak($body);
// Add Redirect tag
$redirect = "https://example.com/connect.php";
$r->addRedirect($redirect);
Header('Content-type: text/xml');
echo $r->toXML();
?>

<!--connect.php-->

<?php 
require 'vendor/autoload.php';
use Plivo\Response;
$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>
<?php

require 'vendor/autoload.php';
use Plivo\Response;
// Sender's phone numer
$from_number = $_REQUEST["From"];
// Receiver's phone number - Plivo number
$to_number = $_REQUEST["To"];
// The SMS text message which was received
$text = $_REQUEST["Text"];
// Output the text which was received, you could
// also store the text in a database.
// echo("Message received from $from_number : $text");
$params = array('src' => $to_number, 'dst' => $from_number);
$body = "Thank you for your message.";
// Generate a Message XML with the details of
// the reply to be sent.
$r = new Response();
$r->addMessage($body, $params);
Header('Content-type: text/xml');
echo $r->toXML();
?>

<!--
Sample Output
Message received from 3333333333 : Hello, from Plivo
<Response>
   <Message dst="2222222222" src="1111111111">Thank you for your message</Message>
</Response>
-->
<?php

require 'vendor/autoload.php';
use Plivo\Response;
# 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 'vendor/autoload.php';
use Plivo\RestAPI;
# 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);
Esempio n. 8
0
<?php

require 'vendor/autoload.php';
use Plivo\Response;
$r = new Response();
// Add Speak tag
$body = "Sending Digits";
$r->addSpeak($body);
// Add DTMF tag
$dtmf = "12345";
$r->addDTMF($dtmf);
Header('Content-type: text/xml');
echo $r->toXML();
/*
Sample Output
<Response>
    <Speak>Sending Digits</Speak>
    <DTMF>12345</DTMF>
</Response>
*/
Esempio n. 9
0
<?php

require 'vendor/autoload.php';
use Plivo\Response;
# 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'];
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
use Plivo\Response;
$auth_token = "Your AUTH_TOKEN";
$signature = $_SERVER["HTTP_X_PLIVO_SIGNATURE"];
$url = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$uri = explode('?', $url);
$uri1 = $uri[0];
$parse = parse_url($url, PHP_URL_QUERY);
parse_str($parse, $get_array);
$post_params = $_POST;
$array = array_merge($get_array, $post_params);
$valid = RestAPI::validate_signature($uri1, $array, $signature, $auth_token);
$valid_message = "Signature is " . ($valid ? "" : "not ") . "valid.";
// Report signature validity to web server log
error_log($valid_message);
if ($valid) {
    // Signature is valid
    $r = new Response();
    // Generate a Speak XML with the details of the text to play on the call.
    $body = 'Hi, Calling from Plivo';
    // Add speak element
    $r->addSpeak($valid_message);
    Header('Content-type: text/xml');
    echo $r->toXML();
} else {
    // Signature is invalid
    error_log("Error! Something is wrong. Please check!");
}
Esempio n. 11
0
<?php

require 'vendor/autoload.php';
use Plivo\Response;
$from_number = $_REQUEST['From'];
$caller = array('1111111111', '2222222222', '3333333333');
$r = new Response();
if (in_array($from_number, $caller)) {
    $params = array('reason' => 'rejected');
    $r->addHangup($params);
} else {
    $body = "Hello, from Plivo!";
    $r->addSpeak($body);
}
Header('Content-type: text/xml');
echo $r->toXML();
/*
Sample output when From number is in blacklist
<Response>
    <Hangup reason="rejected"/>
</Response>

Sample Output when From number is not in blacklist
<Response>
    <Speak>Hello from Plivo</Speak>
</Response>
*/
<?php

require 'vendor/autoload.php';
use Plivo\Response;
$r = new Response();
$getdigits_action_url = "https://example.com/transfer_action.php";
$params = array('action' => $getdigits_action_url, 'method' => 'GET', 'timeout' => '7', 'numDigits' => '1', 'retries' => '1', 'redirect' => 'false');
$getDigits = $r->addGetDigits($params);
$getDigits->addSpeak("Press 1 to transfer your call");
$waitparam = array('length' => '10');
$r->addWait($waitparam);
Header('Content-type: text/xml');
echo $r->toXML();
?>

<!-- transfer_action.php -->

<?php 
require 'vendor/autoload.php';
use Plivo\RestAPI;
$digit = $_REQUEST['Digits'];
$call_uuid = $_REQUEST['CallUUID'];
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
error_log($digit);
error_log($call_uuid);
$p = new RestAPI($auth_id, $auth_token);
if ($digit == "1") {
    $params = array('call_uuid' => $call_uuid, 'aleg_url' => 'https://example.com/connect', 'aleg_method' => 'GET');
    $resp = $p->transfer_call($params);
    print_r($resp);
<?php

require 'vendor/autoload.php';
use Plivo\Response;
$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 'vendor/autoload.php';
use Plivo\Response;
// 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");
$r->addSpeak($body2, $params2);
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>
*/
Esempio n. 15
0
<?php

require 'vendor/autoload.php';
use Plivo\Response;
# Generate a Record XML
$r = new Response();
$record_params = array('action' => 'https://example.com/record_action', 'method' => 'GET', 'callbackUrl' => 'https://example.com/recording_callback', 'callbackMethod' => 'GET');
$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'];
print "Record URL : {$record_url}";
print "Recording Duration : {$record_duration}";
print "Recording ID : {$record_id}";
?>

<!--recording_callback.php-->

<?php 
# Callback URL Example
$record_url = $_REQUEST['record_url'];
$record_duration = $_REQUEST['recording_duration'];
$record_id = $_REQUEST['recording_id'];
<?php

require 'vendor/autoload.php';
use Plivo\Response;
// Simultaneous dialing is useful when there are SIP users and numbers that you want to dial.
// The first call that connects will cancel all other tries.
$r = new Response();
// Add Dial tag
$d = $r->addDial();
// Add Number tag
$number1 = "1111111111";
$d->addNumber($number1);
$number2 = "2222222222";
$d->addNumber($number1);
$user1 = "sip:abcd1234@phone.plivo.com";
$d->addUser($user1);
Header('Content-type: text/xml');
echo $r->toXML();
/*
Sample Output
<Response>
    <Dial>
        <Number>1111111111</Number>
        <Number>2222222222</Number>
        <User>sip:abcd1234@phone.plivo.com</User>
    </Dial>
</Response>
*/
Esempio n. 17
0
<?php

require 'vendor/autoload.php';
use Plivo\Response;
$r = new Response();
// Add Speak tag
$body = "Connecting your call..";
$r->addSpeak($body);
$params = array('action' => 'https://example.com/dial_status.php', 'method' => 'GET');
// Add Dial tag
$d = $r->addDial($params);
$number = "1111111111";
$d->addNumber($number);
Header('Content-type: text/xml');
echo $r->toXML();
?>

<!--dial_status.php-->

<?php 
// Print the Dial Details
$status = $_REQUEST['DialStatus'];
$aleg = $_REQUEST['DialALegUUID'];
$bleg = $_REQUEST['DialBLegUUID'];
echo "Status = {$status} , Aleg UUID = {$aleg} , Bleg UUID = {$bleg}";
/*
Sample Output
<Response>
    <Speak>Connecting your call..</Speak>
    <Dial action="https://glacial-harbor-8656.herokuapp.com/testing.php/dial_status" method="GET">
        <Number>1111111111</Number>
<?php

require 'vendor/autoload.php';
use Plivo\Response;
// 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>
*/
<?php

require 'vendor/autoload.php';
use Plivo\Response;
// 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>
*/
Esempio n. 20
0
                $r->addSpeak($WRONG_INPUT_MESSAGE);
            }
        }
        Header('Content-type: text/xml');
        echo $r->toXML();
        break;
}
?>

<!--phone_tree.php-->

<?php 
require 'vendor/autoload.php';
use Plivo\Response;
$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);