Using this guide, you can set up a development environment in five minutes to trigger a PHLO.
To get started, install PHP, the Composer dependency manager, the Laravel web framework, and Plivo’s PHP SDK.
Operating System | Instructions |
---|---|
macOS | Install PHP using the official macOS installer or by downloading and installing it. |
Linux | Download and install PHP using your favorite package installer. |
Windows | Use the official Windows installer. |
All modern PHP frameworks use the Composer dependency manager; we highly recommend using it as the package manager for your web project. Follow the instructions to download and install Composer for macOS and Linux and for Windows, or follow the steps below.
Run this command in Terminal:
php ~/Downloads/composer.phar --version
Note: PHAR (PHP archive) is an archive format for PHP that can be run on the command line.
Copy the file to /usr/local/bin and make it executable:
cp ~/Downloads/composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
If your PATH doesn’t include /usr/local/bin directory, we recommend adding it so that you can access it globally. To check if the path has /usr/local/bin, enter
echo $PATH
If necessary, run these commands to update the $PATH:
export PATH = $PATH:/usr/local/bin
source ~/.bash_profile
You can also check the version of Composer by running this command:
composer --version.
Run the command
curl -sS https://getcomposer.org/installer | php
Make the composer.phar file executable:
chmod +x composer.phar
Note: PHAR (PHP archive) is an archive format for PHP that can be run on the command line.
Run this 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: Allow Windows Installer for Composer to make changes to your php.ini file.
Run the Composer command.
composer -V
Install the Laravel web framework by running the command
composer require laravel/installer
Once you have Laravel installed, create a project directory using the command mkdir mylaravelapp
, then change to that directory and create a new Laravel project.
composer create-project laravel/laravel quickstart --prefer-dist
This command creates a directory named quickstart with the necessary folders and files for development.
To install the stable release of the Plivo SDK, run this command in the project directory:
composer require plivo/plivo-php
To install a specific release, run this command in the project directory:
composer require plivo/plivo-php:4.15.0
Alternatively, you can download source code from GitHub and run
composer install
The composer
command generates the autoload files, which you can include in your PHP source code by using the line
<?php
require 'vendor/autoload.php'
Create and configure a PHLO, then integrate the PHLO into your application workflow by making an API request to trigger the PHLO with the required payload.
You can run a PHLO with static payload values by entering specific values in fields like from and to on the PHLO console.
To deliver a dynamic payload instead of a static one, define the payload keys as Liquid templates on the PHLO console and pass the values at runtime.
Change the directory to the project directory and run this command to create a Laravel controller named PhloController in the app/http/controllers/ directory.
php artisan make:controller PhloController
Edit app/http/controllers/phloController.php and paste into it the code below for either a static or dynamic payload.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
namespace App\Http\Controllers;
require '../../vendor/autoload.php';
use Plivo\Resources\PHLO\PhloRestClient;
use Plivo\Exceptions\PlivoRestException;
class PhloController extends Controller
{
public function triggerPhlo()
{
$client = new PhloRestClient("<auth_id>", "<auth_token>");
$phlo = $client->phlo->get("<phlo_id>");
try {
$response = $phlo->run(["from" => "<Caller_ID>", "to" => "<Destination_Number>"]); // These are the fields entered in the PHLO console
echo json_encode($response);
} catch (PlivoRestException $ex) {
echo json_encode($ex);
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
namespace App\Http\Controllers;
require '../../vendor/autoload.php';
use Plivo\Resources\PHLO\PhloRestClient;
use Plivo\Exceptions\PlivoRestException;
class PhloController extends Controller
{
public function triggerPhlo()
{
$client = new PhloRestClient("<auth_id>", "<auth_token>");
$phlo = $client->phlo->get("<phlo_id>");
try {
$response = $phlo->run();
echo json_encode($response);
} catch (PlivoRestException $ex) {
echo json_encode($ex);
}
}
}
To add a route for the outbound function in the PhloController class, edit routes/web.php and add this line at the end of the file:
Route::match(['get', 'post'], '/triggerphlo', 'PhloController@triggerPhlo');
Route::match(['get', 'post'], '/triggerphlo', 'App\Http\Controllers\PhloController@triggerPhlo');
Save the file and run it.
php artisan serve
Your local development server will be started and you can test the Laravel application via the URL http://localhost:8000/triggerphlo/.