When you sign up with Plivo, you will start with a free trial account to experiment with and learn about our services. This free trial account comes with free credits. If you wish to continue with our service, you can add more credits and purchase a number by clicking here. Add a number and credits to your account to start testing the full range of our voice and SMS service features.
Sign up here to get your free Plivo account today.
Follow these steps to successfully sign up for a free trial account:
If you have any issues creating a Plivo account, please reach out to our Support Team for assistance.
Start your implementation with Plivo to make/receive calls using PHLO or the traditional API/XML way. PHLO allows you to create the call flows using its intuitive canvas and deploy it with few clicks. Refer to the instructions from the respective tabs below to start your integration with PHLO or XML as you wish.
To make your first outbound call, you can create and deploy a PHLO in just a few clicks using the PHLO canvas. PHLO also lets you visually construct your entire use-case. With PHLO, only pay for calls you make/receive. Building with PHLO is free.
Create a PHLO to make your first outbound call by following these instructions:
You must set up and install PHP and Plivo’s PHP SDK to make your first call. Here’s how.
Operating System | Instructions |
---|---|
OS X | You can install PHP using the official installer. You can also install it from here. |
Linux | To install PHP on Linux you can find the instructions here. |
Windows | To instll PHP on Windows you can use the official installer. |
Composer is a dependency manager for PHP that is used in all modern PHP frameworks, such as Symfony and Laravel. We highly recommend using Composer as the package manager for your web project.
Run the following command in Terminal in order to run the composer:
$ php ~/Downloads/composer.phar --version
Note: PHAR (PHP archive) is an archive format for PHP that can be run on the command line
Run the following command to make it executable:
$ cp ~/Downloads/composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer
$ Make sure you move the file to bin directory.
To check if the path has /usr/local/bin, use
$ echo $PATH
If the path is different, use the following command to update the $PATH:
$ export PATH = $PATH:/usr/local/bin
$ source ~/.bash_profile
Note: If your PATH doesn’t include /usr/local/bin directory, we recommend adding it so that you can access it globally.
You can also check the version of Composer by running the following command:
$ composer --version.
Run the following command:
$ curl -sS https://getcomposer.org/installer | php
Run the following command to make the composer.phar file as executable:
$ chmod +x composer.phar
Note: PHAR (PHP archive) is an archive format for PHP that can be run on the command line
Run the following command to make Composer globally available for all system users:
$ mv composer.phar /usr/local/bin/composer
Download and run the Windows Installer for Composer.
Note: Make sure to allow Windows Installer for Composer to make changes to your php.ini file.
Run the Composer command.
$ composer -V
Create a project directory, run the following command:
$ mkdir myphpapp
Change the directory to our project directory in the command line:
$ cd myphpapp
To install the stable release, run the following command in the project directory:
$ composer require plivo/plivo-php
Alternatively, you can download this source and run
$ composer install
Once you have created and setup your PHP dev envrironment, you can go to your Plivo Consolse and copy the PHLO_ID. Integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload.
You can choose to either configure the mandatory params required for a PHLO while creating the PHLO itself or, you can pass the params as payload while triggering the PHLO from your app.
Now, create a file called TriggerPhlo.php and paste the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require 'vendor/autoload.php';
use Plivo\Resources\PHLO\PhloRestClient;
use Plivo\Exceptions\PlivoRestException;
$client = new PhloRestClient("YOUR_AUTH_ID", "YOUR_AUTH_TOKEN");
$phlo = $client->phlo->get("YOUR_PHLO_ID");
try {
$response = $phlo->run();
print_r($response);
} catch (PlivoRestException $ex) {
print_r($ex);
}
To use dynamic values for the parameters, use the liquid templating params while creating the PHLO and pass the values while triggering the PHLO.
Now, create a file called TriggerPhlo.php and paste the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require 'vendor/autoload.php';
use Plivo\Resources\PHLO\PhloRestClient;
use Plivo\Exceptions\PlivoRestException;
$client = new PhloRestClient("YOUR_AUTH_ID", "YOUR_AUTH_TOKEN");
$phlo = $client->phlo->get("YOUR_PHLO_ID");
try {
$response = $phlo->run(["from" => "+14157778888", "to" => "+14157778889"]); // These are the fields entered in the PHLO console
print_r($response);
} catch (PlivoRestException $ex) {
print_r($ex);
}
Get your Auth_ID and Auth_token from your dashboard
You can find the PHLO_ID on the PHLO Listing page.
Save the file and use the below command to run your code.
$ php TriggerPhlo.php
Create and deploy a PHLO to receive your first inbound call with a few clicks on the PHLO canvas. PHLO also lets you visually construct your entire use-case. With PHLO, only pay for calls you make/receive. Building with PHLO is free.
You can create a PHLO by referring to the below instructions to receive your first incoming call:
Once you have created and configured your PHLO, assign your PHLO to a Plivo number.
If you have not purchased a phone number yet, you can buy a phone number(s) by referring to the instructions available here.
You can now make a call to your Plivo phone number to receive an incoming call and see how the inbound call is handled using PHLO.
For more information about creating a PHLO app, see the PHLO User Guide.
For information on components and their variables, see the PHLO Components Library.
To forward an incoming call, you can create and deploy a PHLO with a few clicks on the PHLO canvas.
You can create a PHLO by referring to the below instructions to forward an incoming call:
Once you have created and configured your PHLO, assign your PHLO to a Plivo number.
If you have not purchased a phone number yet, you can buy a phone number(s) by referring to the instructions available here.
You can now make a call to your Plivo phone number and see how the inbound call is forwarded to the phone number specified in the PHLO.
For more information about creating a PHLO app, see the PHLO User Guide.
For information on components and their variables, see the PHLO Components Library.
You must set up and install PHP and Plivo’s PHP SDK to make your first call. Here’s how.
Operating System | Instructions |
---|---|
OS X | You can install PHP using the official installer. You can also install it from here. |
Linux | To install PHP on Linux you can find the instructions here. |
Windows | To install PHP on Windows you can use the official installer. |
Composer is a dependency manager for PHP that is used in all modern PHP frameworks, such as Symfony and Laravel. We highly recommend using Composer as the package manager for your web project.
Run the following command in Terminal in order to run the composer:
$ php ~/Downloads/composer.phar --version
Note: PHAR (PHP archive) is an archive format for PHP that can be run on the command line
Run the following command to make it executable:
$ cp ~/Downloads/composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer
$ Make sure you move the file to bin directory.
To check if the path has /usr/local/bin, use
$ echo $PATH
If the path is different, use the following command to update the $PATH:
$ export PATH = $PATH:/usr/local/bin
$ source ~/.bash_profile
Note: If your PATH doesn’t include /usr/local/bin directory, we recommend adding it so that you can access it globally.
You can also check the version of Composer by running the following command:
$ composer --version.
Run the following command:
$ curl -sS https://getcomposer.org/installer | php
Run the following command to make the composer.phar file as executable:
$ chmod +x composer.phar
Note: PHAR (PHP archive) is an archive format for PHP that can be run on the command line
Run the following command to make Composer globally available for all system users:
$ mv composer.phar /usr/local/bin/composer
Download and run the Windows Installer for Composer.
Note: Make sure to allow Windows Installer for Composer to make changes to your php.ini file.
Run the Composer command.
$ composer -V
Create a project directory, run the following command:
$ mkdir myphpapp
Change the directory to our project directory in the command line:
$ cd myphpapp
To install the stable release, run the following command in the project directory:
$ composer require plivo/plivo-php
To install a specific release, run the following command in the project directory:
$ composer require plivo/plivo-php:4.3.1
To test the features in the beta release, run the following command in the project directory:
$ composer require plivo/plivo-php:v4.2-beta1
Alternatively, you can download this source and run
$ composer install
This generates the autoload files, which you can include using the following line in your PHP source code to start using the SDK.
<?php
require 'vendor/autoload.php'
This section will guide you through how to use Plivo APIs to make voice calls from your application. First, let’s make sure you meet these prerequisites before we dive into the code.
Plivo Auth Id and Auth Token: You will find your Plivo Auth Id and Auth Token on the home screen of your Plivo Console. Click here to sign-up for a Plivo account if you haven’t already!
Plivo Phone Number(Optional): Purchase numbers from the Numbers section of your Plivo Console and use the same as the caller ID for the outbound call. This number will also help you receive incoming calls as you must have a voice-enabled Plivo phone number to do the same. Please note that you can also purchase numbers using the Numbers API.
Answer Url: When a call is answered by the destination_number, you can control the call flow with the help of the answer_url set in the API request. Plivo will invoke the answer_url specified as soon as the call is answered and expect a valid XML response with instructions to handle the call. For example, you can use https://s3.amazonaws.com/static.plivo.com/answer.xml as answer_url to test your first outgoing call. The XML response of this is:
<Response>
<Speak>Congratulations! You've made your first outbound call!</Speak>
</Response>
As you can tell, the XML above holds instructions to say ‘Congratulations! You’ve made your first outbound call!’ to the callee. You can find the entire list of Plivo XML verbs and their details in the XML Reference section of the website here.
Now, create a file called MakeCall.php and paste the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require 'vendor/autoload.php';
use Plivo\RestClient;
$auth_id = "Your AUTH_ID";
$auth_token = "Your AUTH_TOKEN";
$client = new RestClient($auth_id, $auth_token);
$response = $client->calls->create('+14151234567',
['+14157654321'],
'http://s3.amazonaws.com/static.plivo.com/answer.xml',
'GET');
print_r($response);
Save the file and use the following command to run your code.
php MakeCall.php
In addition to having at least one voice-enabled Plivo phone number that is needed to receive incoming calls (as was mentioned earlier), you need the following:
When a call is received on a Plivo voice-enabled number, you can control the call flow by declaring an answer URL for your Plivo application associated with that Plivo phone number. Plivo will invoke the answer URL specified and expect a valid XML response to handle the call.
Notice how the concept of Answer URLs applies to both outbound API calls as well as incoming calls to your Plivo numbers. In the outbound API call example above, we specified the answer URL along with the make call API request, whereas in the case of incoming calls to Plivo numbers, the answer URL is specified in the Plivo application associated with the phone number.
In addition to requests to the answer URL, Plivo initiates HTTP requests to your application server through the course of a call based on the specific XML elements in your answer XML. Such requests can be broadly classified into two categories:
Action URL requests: XML instructions to carry forward the call are expected in response to these requests. These requests are typically invoked at the end of an XML element’s execution. For example: when an IVR input is received from the caller during a GetInput XML execution.
Callback URL requests: No XML instructions are expected in response to these requests. Such requests serve as webhooks to notify your application server of important events through the course of an XML element’s execution. For example: when a conference participant is muted or unmuted.
To be able to host Answer and Callback URLs and to be able to provide valid XMLs and accept notifications on these URLs respectively, you need to host a webserver at your end.
In this section, we’ll walk you through how to set up a PHP server in under five minutes and start handling incoming calls & callbacks.
Use the following code snippet to start a local server.
1
2
3
4
5
6
7
8
9
10
11
<?php
require '../vendor/autoload.php';
use Plivo\XML\Response;
$response = new Response();
$speak_body = "Hello, you just received your first call";
$response->addSpeak($speak_body);
Header('Content-type: text/xml');
echo($response->toXML());
?>
Save this code in any file (name the file something like receive_call.php
). To run this file on the server, go to the folder where this file resides and use the following command:
php -S localhost:8000
You can choose to run it on any other IP or port that your machine has access to. You should see your basic server app in action on http://localhost:8000/receive_call.php
To receive incoming calls and to handle callbacks, your local server should be able to connect with the Plivo API service. Ngrok is a tunneling software used to expose a web server running on your local machine to the internet. Using Ngrok you can set webhooks that can talk to the Plivo server.
You can download and install ngrok from here. Follow the detailed configuration instructions to get started.
Run ngrok on the port which currently hosts your application. For example, if your port number is 80, run the following command:
./ngrok http <port_on_which_your_local_server_is_running>
This will give you a UI with links that look like ngrok.io/*
which you can use to access your local server using the public network.
New Application
. You can also use Plivo’s Application API.Receive_call
. Enter your server URL (e.g. http://example.com/receive_call.php
) in the Answer URL
field and set the method as POST
. See our Application API docs to learn how to modify your application through our APIs.Create
to save your application.Receive Call
(name of the app) from the Plivo App dropdown list.Update
to save.Make a call to your Plivo number using a regular mobile phone. Plivo will send a request to your Answer URL
requesting for a valid XML response and process the call. Meanwhile, the parameters listed in the XML Request - call status documentation will also be sent to your server.
To forward an incoming call, you need to use Dial XML.
Create a file called forward_call.php
and paste the following code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
require '../vendor/autoload.php';
use Plivo\XML\Response;
$response = new Response();
$params = array(
'action' => "https://www.foo.com/dial_status/",
'method' => "POST",
'redirect' => "true"
);
$dial = $response->addDial($params);
$number = "14153336666"; // call wll be forwarded to this number
$dial->addNumber($number);
Header('Content-type: text/xml');
echo($response->toXML());
Make a call to your Plivo number using a regular mobile phone. Plivo will send a request to your Answer URL
requesting for a valid XML response and process the call. Once Plivo receives the dial XML response, the call will be forwarded to the number defined in the XML. Meanwhile, the parameters listed in the XML Request - call status documentation will also be sent to your server.