<?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;
// 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

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!");
}
<?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>
*/
<?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);
        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);
        } else {
            $r->addSpeak($WRONG_INPUT_MESSAGE);
        }
    }
}