<?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;
$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();