Ejemplo n.º 1
0
 /**
  * Get Specific Message Details
  *
  * @param $uuid
  * @return array
  */
 public function getMessage($uuid)
 {
     if (empty($uuid)) {
         return 'No UUID specified';
     }
     $data = ['record_id' => $uuid];
     return $this->plivo->get_message($data);
 }
Ejemplo n.º 2
0
 /**
  * Plivo constructor.
  * This is an extra layer to support dependency injection.
  */
 public function __construct()
 {
     $this->auth_id = config('plivo.auth-id');
     $this->auth_token = config('plivo.auth-token');
     $this->url = config('plivo.api-url');
     $this->version = config('plivo.api-version');
     $this->api = $this->url . "/" . $this->version . "/Account/" . $this->auth_id;
     parent::__construct($this->auth_id, $this->auth_token, $this->url, $this->version);
 }
Ejemplo n.º 3
0
 /**
  * Checks if a message is authentic from Plivo.
  *
  * @throws \InvalidArgumentException
  */
 protected function validateRequest()
 {
     $data = $_POST;
     $url = $this->url;
     $signature = $_SERVER['X-Plivo-Signature'];
     $authToken = $this->authToken;
     if (!$this->plivo->validate_signature($url, $data, $signature, $authToken)) {
         throw new \InvalidArgumentException('This request was not able to verify it came from Plivo.');
     }
     return true;
 }
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
$response = $p->get_cdrs();
// print_r ($response);
/* 
Sample Output
( 
    [status] => 200 
    [response] => Array ( 
        [api_id] => 22852b7c-ae03-11e4-a2d1-22000ac5040c 
        [meta] => Array ( 
            [limit] => 20 
            [next] => /v1/Account/XXXXXXXXXXXXXXX/Call/?limit=20&offset=20 
            [offset] => 0 
            [previous] => 
            [total_count] => 124 
        ) [objects] => Array ( 
            [0] => Array ( 
                [bill_duration] => 8 
                [billed_duration] => 60 
                [call_direction] => outbound 
                [call_duration] => 8 
                [call_uuid] => dd9b3414-adc8-11e4-aed8-377ffe01233f 
                [end_time] => 2015-02-06 10:25:20+04:00 
                [from_number] => 
                [parent_call_uuid] => d66cc0a4-adc8-11e4-ac44-377ffe01233f 
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
// Fetch the details
$response = $p->get_messages();
// Print the response
print_r($response['response']);
// Filter the response
$params = array('limit' => '2', 'offset' => '0', 'message_direction ' => 'outbound', 'message_state' => 'sent', 'subaccount' => 'SubAccount_AUTH_ID');
// Fetch the details
$response = $p->get_messages($params);
// Print the response
print_r($response['response']);
?>

<!--
Sample Output without Filters
(
    [api_id] => f9adfd4a-a264-11e4-a2d1-22000ac5040c 
    [meta] => Array ( 
        [limit] => 2 
        [next] => /v1/Account/XXXXXXXXXXXXXXX/Message/?message_state=sent&limit=2&offset=2&message_direction+=outbound 
        [offset] => 0 
        [previous] => 
        [total_count] => 70 
    ) [objects] => Array ( 
        [0] => Array ( 
Ejemplo n.º 6
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
# To record a call
$params = array('call_uuid' => "xxxxxxxxxxx", 'time_limit' => '40', 'callback_url' => "https://example.com/record_action/", 'callback_method' => "GET", 'transcriptionType' => 'auto', 'transcriptionUrl' => "https://example.com/transcription/", 'transcriptionMethod' => 'GET');
$resp = $p->record($params);
print_r($resp);
# To stop recording a call
$params = array('call_uuid' => "xxxxxxxxxxx");
$resp = $p->stop_record($params);
print_r($resp);
# To record a conference call
$params = array('conference_name' => "demo", 'callback_url' => "https://example.com/record_action/", 'callback_method' => "GET");
$resp = $p->record_conference($params);
print_r($resp);
# To stop recording a conference call
$params = array('conference_name' => "demo");
$resp = $p->stop_record_conference($params);
print_r($resp);
Ejemplo n.º 7
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "MAMWYYYZLJNTVLYJMYYJ";
$auth_token = "MWQzZDZkZTU1OTc1OGY5N2IyYTJjYTdiNDIwYmQz";
$p = new RestAPI($auth_id, $auth_token);
// Send a message
$params = array('src' => '7772823928', 'dst' => '+919009472525', 'text' => 'Hi, Message from Plivo');
// Send message
$response = $p->send_message($params);
// Print the response
echo "Response : ";
print_r($response['response']);
// Print the Api ID
echo "<br> Api ID : {$response['response']['api_id']} <br>";
// Print the Message UUID
echo "Message UUID : {$response['response']['message_uuid'][0]} <br>";
Header('Content-type: text/xml');
echo $r->toXML();
?>

<!--recording_action.php-->

<?php 
require 'vendor/autoload.php';
use Plivo\RestAPI;
$digit = $_REQUEST['Digits'];
$uuid = $_REQUEST['CallUUID'];
print "Digit : {$digit}";
print "Call UUID : {$uuid}";
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
if ($digit == "1") {
    $params = array('call_uuid' => $uuid);
    $response = $p->record($params);
    print "URL : {$response['response']['url']}";
    print "Recording ID : {$response['response']['recording_id']}";
    print "API ID : {$response['response']['api_id']}";
    print "Message : {$response['response']['message']}";
} else {
    print "invalid";
}
/*
Sample Output
<Response>
    <GetDigits action="https://glacial-harbor-8656.herokuapp.com/testing.php/recording_action" method="GET" timeout="7" numDigits="1" retries="1" redirect="false">
        <Speak>Press 1 to record this call</Speak>
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$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
    // 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.
    error_log("Message received from {$from_number}: {$text}");
} else {
    // Signature is invalid
    error_log("Error! Something is wrong. Please check!");
Ejemplo n.º 10
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
# Get all numbers
$params = array('limit' => '10', 'offset' => '0');
#$response = $p->get_numbers($params);
#print_r ($response);
/*
Sample Output
(
    [status] => 200
    [response] => Array
    (
        [api_id] => b5b9e238-b688-11e4-ac1f-22000ac51de6
        [meta] => Array
        (
            [limit] => 10
            [next] => 
            [offset] => 0
            [previous] => 
            [total_count] => 2
        )

        [objects] => Array
        (
            [0] => Array
            (
Ejemplo n.º 11
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
// Create an Endpoint
$params = array('username' => 'Testing', 'password' => 'TestingCity', 'alias' => 'Sample address');
$response = $p->create_endpoint($params);
// print_r ($response['response']);
/*
Sample Output
( 
    [alias] => Sample address 
    [api_id] => f800f950-ac43-11e4-ac1f-22000ac51de6 
    [endpoint_id] => 32969375408354 
    [message] => created 
    [username] => Testing150204080105 
)
*/
// Get Details of all existing Endpoints
$response = $p->get_endpoints();
// print_r ($response['response']);
/*
Sample Output
( 
    [api_id] => 13632e02-ac44-11e4-b423-22000ac8a2f8 
    [meta] => Array ( 
        [limit] => 20 
        [next] => 
Ejemplo n.º 12
0
$r->addWait($waitparam);
Header('Content-type: text/xml');
echo $r->toXML();
?>

<!--speak_action.php-->

<?php 
require 'vendor/autoload.php';
use Plivo\RestAPI;
$r = new Response();
$digit = $_REQUEST['Digits'];
$call_uuid = $_REQUEST['CallUUID'];
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
if ($digit == "1") {
    $params = array('call_uuid' => $call_uuid, 'text' => 'Hello from Speak API', 'voice' => 'WOMAN', 'language' => 'en-GB');
    $resp = $p->speak($params);
    print_r($resp);
} else {
    print "WrongInput";
}
/*
Sample Output
<Response>
    <GetDigits action="http://morning-ocean-4669.herokuapp.com/speak_action/" method="GET" numDigits="1" redirect="false" retries="1" timeout="7">
        <Speak>Press 1 to listen to a message</Speak>
    </GetDigits>
    <Wait length="10" />
</Response>
Ejemplo n.º 13
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
// Get account details
$response = $p->get_account();
// print_r ($response['response']);
/*
Sample Output
( 
    [account_type] => standard 
    [address] => Example add 
    [api_id] => 096ca42e-ac34-11e4-96e3-22000abcb9af 
    [auth_id] => xxxxxxxxxxxxxxxx 
    [auto_recharge] => False
    [billing_mode] => prepaid 
    [cash_credits] => 79.40625 
    [city] => Test Place 
    [name] => User 
    [resource_uri] => /v1/Account/xxxxxxxxxxxxxxxx/ 
    [state] => 
    [timezone] => Asia/Kolkata 
)
*/
// Modify account
$params = array('name' => 'Testing', 'city' => 'Testing City', 'address' => 'Sample address', 'timezone' => 'Indian/Mauritius');
$response = $p->modify_account($params);
// print_r ($response['response']);
Ejemplo n.º 14
0
<!--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);
    print "URL : {$resp['response']['url']}";
    print "Recording ID : {$resp['response']['recording_id']}";
    print "API ID : {$resp['response']['api_id']}";
    print "Message : {$resp['response']['message']}";
} else {
    print "invalid";
}
/*
Sample Output
<Response>
    <Speak>
        You will now be placed into a demo conference. This is brought to you by Plivo. To know more visit us at plivo.com
    </Speak>
Ejemplo n.º 15
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
# API ID is returned for every API request.
# Request UUID is request id of the call. This ID is returned as soon as the call is fired irrespective of whether the call is answered or not
$params = array('to' => '2222222222', 'from' => '1111111111', 'answer_url' => "https://example.com/speak", 'answer_method' => "GET");
# Make an outbound call
$response = $p->make_call($params);
puts("API ID : #{$response['api_id']}");
puts("Request UUID : #{$response['request_uuid']}");
/* 
Sample Output
API ID : 32cba792-ae01-11e4-b153-22000abcaa64 
Request UUID : 5b2db3d3-f478-4b63-992c-e47c527572e8 
*/
# Call UUID is th id of a live call. This ID is returned only after the call is answered.
$params1 = array('status' => 'live');
# Get the details of all live calls
$response = $p->get_live_calls($params1);
$uuids = $response['response']['calls'];
// Looping through the call uuids
foreach ($uuids as $value) {
    print_r("Call UUID : {$value} <br>");
}
/*
Sample Output
Call UUID : a60f44dc-926f-11e4-82f5-b559cbfe39b9
Ejemplo n.º 16
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
$params = array('record_id' => '0936ec98-7c4c-11e4-9bd8-22000afa12b9');
// Fetch the details
$response = $p->get_message($params);
// Print the response
print_r($response['response']);
// Print the number of SMS units
print "Units : {$response['response']['units']}";
// Print the status of the message
print "Message State : {$response['response']['message_state']}";
?>

<!--
Sample Output
( 
    [api_id] => 0a7cf0e6-a264-11e4-a2d1-22000ac5040c 
    [from_number] => 1111111111 
    [message_direction] => outbound 
    [message_state] => delivered 
    [message_time] => 2014-12-05 10:57:54+04:00 
    [message_type] => sms 
    [message_uuid] => 0936ec98-7c4c-11e4-9bd8-22000afa12b9 
    [resource_uri] => /v1/Account/XXXXXXXXXXXX/Message/0936ec98-7c4c-11e4-9bd8-22000afa12b9/ 
    [to_number] => 2222222222 
    [total_amount] => 0.02600 
Ejemplo n.º 17
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
$plivo_number = "1111111111";
$params = array('to' => '1111111111<2222222222', 'from' => $plivo_number, 'answer_url' => "https://example.com/conference_xml.php", 'answer_method' => "GET");
$response = $p->make_call($params);
print_r($response);
/* Sample Output
( 
    [status] => 201 
    [response] => Array ( 
        [api_id] => 8b32b934-af6e-11e4-b153-22000abcaa64 
        [message] => calls fired 
        [request_uuid] => Array ( 
            [0] => d1187266-b5e8-4a1d-bd8d-b0a4395f08f6 
            [1] => 0c88ed10-fde4-4e6e-8c7c-08ebeee5e856 
        ) 
    ) 
)
*/
Ejemplo n.º 18
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
$params = array('country_iso' => 'GB');
$response = $p->pricing($params);
print_r($response);
/*
Sample Output
( 
    [status] => 200 
    [response] => Array ( 
        [api_id] => 36d239fa-ac4e-11e4-96e3-22000abcb9af 
        [country] => United Kingdom 
        [country_code] => 44 
        [country_iso] => GB 
        [message] => Array ( 
            [inbound] => Array ( 
                [rate] => 0.00000 
            ) [outbound] => Array ( 
                [rate] => 0.03680 
            ) [outbound_networks_list] => Array ( 
                [0] => Array ( 
                    [group_name] => United Kingdom - All 
                    [rate] => 0.03680 
                ) 
            ) 
        ) [phone_numbers] => Array ( 
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
# Search for new number
$params = array('country_iso' => 'US', 'type' => 'local', 'pattern' => '210', 'region' => 'Texas');
$response = $p->search_phone_numbers($params);
print_r($response);
/*
Sample Output
(
    [status] => 200
    [response] => Array
    (
        [api_id] => 059936ae-b68a-11e4-af95-22000ac54c79
        [meta] => Array
        (
            [limit] => 20
            [next] => /v1/Account/XXXXXXXXXXXX/PhoneNumber/?limit=20&country_iso=US&pattern=210&region=Texas&offset=20&type=local
            [offset] => 0
            [previous] => 
            [total_count] => 98
        )

        [objects] => Array
        (
            [0] => Array
            (
Ejemplo n.º 20
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
$params = array('record_id' => '6e699c0a-af55-11e4-91ce-377ffe01233f');
$response = $p->get_cdr($params);
// Print the response
print_r($response);
/* 
Sample Output
( 
    [status] => 200 
    [response] => Array ( 
        [api_id] => 06b1b1cc-af5c-11e4-b153-22000abcaa64 
        [bill_duration] => 6 
        [billed_duration] => 60 
        [call_direction] => outbound 
        [call_duration] => 6 
        [call_uuid] => 6e699c0a-af55-11e4-91ce-377ffe01233f 
        [end_time] => 2015-02-08 09:43:52+04:00 
        [from_number] => +18583650866 
        [parent_call_uuid] => 
        [resource_uri] => /v1/Account/XXXXXXXXXXXXXXX/Call/6e699c0a-af55-11e4-91ce-377ffe01233f/ 
        [to_number] => 11111111111 
        [total_amount] => 0.03570 
        [total_rate] => 0.03570 
    ) 
)
Ejemplo n.º 21
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
// Create an Application
$params = array('answer_url' => 'http://example.com', 'app_name' => 'Testing');
$response = $p->create_application($params);
// print_r ($response['response']);
/*
Sample Output
( 
    [api_id] => ad7a2eb8-ac45-11e4-b932-22000ac50fac 
    [app_id] => 23061826722302672 
    [message] => created 
) 
*/
// Get Details of all existing Applications
$response = $p->get_applications();
// print_r ($response['response']);
/*
Sample Output
( 
    [api_id] => cff47926-ac45-11e4-b153-22000abcaa64 
    [meta] => Array ( 
        [limit] => 20 
        [next] => 
        [offset] => 0 
        [previous] => 
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
# Link an application to a number
$params = array('number' => '1111111111', 'app_id' => '16638156474000802');
#$response = $p->link_application_number($params);
#print_r ($response);
/*
Sample Output
(
    [status] => 202
    [response] => Array
    (
        [api_id] => 3ca792ba-b68c-11e4-af95-22000ac54c79
        [message] => changed
    )
)
*/
# Unlink an application from an number
$params = array('number' => '1111111111');
$response = $p->unlink_application_number($params);
print_r($response);
/*
Sample Output
(
    [status] => 202
    [response] => Array
Ejemplo n.º 23
0
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);
} else {
    print "WrongInput";
}
/*
Sample Output
<Response>
    <GetDigits action="https://example.com/transfer_action.php" method="GET" numDigits="1" redirect="false" retries="1" timeout="7">
        <Speak>Press 1 to transfer this call</Speak>
    </GetDigits>
    <Wait length="10" />
</Response>
Ejemplo n.º 24
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
// Get Details of all existing Applications
$params = array('limit' => '2', 'offset' => '0');
$response = $p->get_applications($params);
// print_r ($response['response']);
/*
Sample Output
( 
    [api_id] => cff47926-ac45-11e4-b153-22000abcaa64 
    [meta] => Array ( 
        [limit] => 20 
        [next] => 
        [offset] => 0 
        [previous] => 
        [total_count] => 2
    ) [objects] => Array ( 
        [0] => Array ( 
            [answer_method] => POST 
            [answer_url] => http://example.com 
            [app_id] => 23061826722302672 
            [app_name] => Testing 
            [default_app] => 
            [default_endpoint_app] => 
            [enabled] => 1 
            [fallback_answer_url] => 
Ejemplo n.º 25
0
<?php

require 'vendor/autoload.php';
use Plivo\RestAPI;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$p = new RestAPI($auth_id, $auth_token);
$params = array('call_uuid' => 'fcef9018-aec6-11e4-8449-c73b3246dc2a');
// Get all Live Calls
$response = $p->get_live_call($params);
print_r($response);
/*
Sample Output
( 
    [status] => 200 
    [response] => Array ( 
        [calls] => Array (
            [0] => a60f44dc-926f-11e4-82f5-b559cbfe39b9
            [1] => af399206-926f-11e4-8b6f-fd067af138be
        )
        [api_id] => 44abd2a4-aec7-11e4-ac1f-22000ac51de6  
    ) 
)
*/
$uuids = $response['response']['calls'];
// Looping through the call uuids
foreach ($uuids as $value) {
    print_r("Calls : {$value} <br>");
}
/* 
Sample Output