Mar 3, 2022
5 mins

How to Connect a Call to a Second Person the Low-Code Way Using PHLO

Plivo's SMS API and Voice API enables businesses to communicate with their customers at global scale. Sign up for free now.

PHLO
Browser SDK
How To

Overview

Click-to-call enables your website users to engage with your support and sales teams on the website itself. Sometimes they want to speak to someone via their handset but initiate the call online or talk to someone directly from the website. You can implement this click-to-call use case using Plivo’s Browser SDK.

How it works

The Plivo Browser SDK lets you make and receive calls using Plivo applications directly from any web browser.
User enters their phone number in the settings. When a call is placed, the user's handset is called first, then the call is connected to the destination number.

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. You must have a voice-enabled Plivo phone number to receive incoming calls; you can rent numbers from the Numbers page of the Plivo console, or by using the Numbers API. Click-to-call requires JavaScript; we recommend using Node.js. If this is your first time triggering a PHLO with Node.js, follow our instructions to set up a Node.js development environment and a web server and safely expose that server to the internet.

Create a PHLO to handle call logic

To create a PHLO, visit the PHLO page of the Plivo console. If this is your first PHLO, the PHLO page will be empty.

  • Click Create New PHLO.
  • In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.

Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.

  • Click the Start node to open the Configuration tab, and then enter the information to retrieve from the HTTP Request payload — in this case key names are destinationNumber and phoneMeNumber. The values will remain blank as we will receive them when the request is made by the browser.
  • Validate the configuration by clicking Validate. Do the same for each node as you go along.
  • From the list of components on the left side, drag and drop the Initiate Call component onto the canvas. This adds an Initiate Call node onto the canvas. When a component is placed on the canvas it becomes a node.
  • Draw a line to connect the Start node’s API Request trigger state to the Initiate Call node.
  • In the Configuration tab of the Initiate Call node, give the node a name. To enter values for the From and To fields, enter two curly brackets to view all available variables, and choose the appropriate ones. The values for the numbers will be retrieved from the HTTP Request payload you defined in the Start node. Here From is 14159142884 and To is {{Start.http.params.phoneMeNumber}}.
  • From the list of components on the left side, drag and drop the Call Forward component onto the canvas. Draw a line to connect the Answered trigger state of the Initiate Call node with the Call Forward node.
  • Configure the Call Forward node to initiate call forward to another user. To enter values for the From and To fields, enter two curly brackets to view all available variables, and choose the appropriate ones. The values for the numbers will be retrieved from the HTTP Request payload you defined in the Start node. Here From is {{Start.http.params.phoneMeNumber}} and To is {{Start.http.params.destinationNumber}}.
  • After you complete and validate the node configurations, give the PHLO a name by clicking in the upper left, then click Save.
  • From the list of components on the left side, drag and drop the Call Forward component onto the canvas.
  • Draw a line to connect the Start node’s Incoming call trigger state to the Call Forward node.
  • In the Configuration tab of the Call Forward node, give the node a name. To enter values for the From and To fields, enter two curly brackets to view all available variables, and choose the appropriate ones. The values for the numbers will be retrieved from the HTTP Request payload you defined in the Start node. Here From is {{Start.http.params.header1}}. and To is {{Start.http.params.to}}.
  • After you complete and validate the node configurations, give the PHLO a name by clicking in the upper left, then click Save.

Your complete PHLO should look like this:

Click to Call

Set up the demo application locally

Download and modify the code to trigger the PHLO.

  • Clone the repository from GitHub.
$ git clone https://github.com/plivo/click2call-webRTC.git
  • Change your working directory to click2call-webRTC.
$ cd click2call-webRTC
  • Install the necessary dependencies using the package.json file.
$ npm install
  • Edit the .env file. Replace the auth placeholders with your authentication credentials from the Plivo console. Enter your PHLO ID, which you can find on the Plivo console.
PORT="8080"
PLIVO_AUTH_ID="<auth_id>"
PLIVO_AUTH_TOKEN="<auth_token>"
PHLO_ID="<phlo_url>"
  • Edit /client/src/index.jsx and replace the caller_id placeholder with a Plivo number.
1
2
3
4
5
6
const customCallerId = <caller_id>;
const extraHeaders = {
    'X-PH-Test1': 'test1',
    'X-PH-callerId': customCallerId
};
this.plivoBrowserSdk.client.call(dest, extraHeaders);

A review of the code

Let‘s walk through what the code does. The PHLO can be triggered either by an incoming call or an HTTP request.

Broswer SDK call

When someone clicks on an application button to initiate a call, we can use the Browser SDK‘s call() method to initiate a call from the application endpoint to the destination phone number. In this case our PHLO is the endpoint, so our outbound call is treated as an incoming call to our PHLO. When the request we make from the browser reaches the endpoint, the browser is connected to Plivo via the endpoint and the endpoint is attached to the PHLO, so when the browser makes a request to Plivo as an incoming call, Plivo connects to the endpoint, which in turn triggers the PHLO to forward the call to the destination number.

The code looks like this.

1
2
3
4
5
6
const customCallerId = <caller_id>;
const extraHeaders = {
    'X-PH-Test1': 'test1',
    'X-PH-callerId': customCallerId
};
this.plivoBrowserSdk.client.call(dest, extraHeaders);

Here the extraHeaders is used to pass the caller_id for a call initiated by the broswer.

Click-to-call

Click-to-call is a more complicated use case because it requires us to actually send an HTTP request with a payload to the PHLO endpoint. Remember that we‘re making a call to our user‘s handset first, then connecting to the destination once the first call is answered. We need to get both phone numbers from the application and send them to the server. The code looks like this.

1
2
3
4
5
6
7
8
9
10
let XMLReq = new XMLHttpRequest();
XMLReq.open("POST", "/makeCall");
XMLReq.setRequestHeader("Content-Type", "application/json");
XMLReq.onreadystatechange = function() {
    console.log('response text', XMLReq.responseText);
}
XMLReq.send(JSON.stringify({
    "src": this.state.phoneMeNumber,
    "dst": dest
}));

We need to listen for this request on the server. Once we receive the request and get the numbers from the payload, we set up another HTTP request that sends this data to the PHLO.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// when we receive an http post request
app.post('/makeCall/', function(req, res) {
    console.log(req.fields);

    jsonObject = JSON.stringify({
        "phoneMeNumber": req.fields.src,
        "destinationNumber": req.fields.dst,
    });
    
    // prepare the header
    let postHeaders = {
        'Content-Type': 'application/json',
        'Authorization': 'Basic ' + new Buffer.from(process.env.<auth_id> +':' + process.env.<auth_token>).toString('base64')
    };
    
    // set the post options
    let postOptions = {
        port: 443,
        host: 'phlo-runner-service.plivo.com',
        path: process.env.<phlo_id>,
        method: 'POST',
        headers: postHeaders,
    };
    
    // do the POST request
    let reqPost = https.request(postOptions, function(response) {
        console.log("statusCode: ", response.statusCode);
        response.on('data', function(d) {
            console.info('POST result:\n');
            process.stdout.write(d);
            console.info('\n\nPOST completed');
            res.send(d);
        });
    });
    
    // write the json data
    console.log(jsonObject);
    reqPost.write(jsonObject);
    reqPost.end();
    reqPost.on('error', function(e) { // log any errors
        console.error(e);
    });
})

Assign the PHLO to a Plivo number

Once you’ve created and configured your PHLO, assign it to a Plivo number.

  • On the Numbers page of the console, under Your Numbers, click the phone number you want to use for the PHLO.
  • In the Number Configuration box, select PHLO from the Application Type drop-down.
  • From the PHLO Name drop-down, select the PHLO you want to use with the phone number, then click Update Number.
Assign PHLO to a Plivo Number

Test

Run these commands.

npm run watch
npm run start

You should see your basic server application running at http://localhost:8080/. Set up ngrok to expose your local server to the internet. Now make a call from your browser-based application to test it.

Note: If you’re using a Plivo Trial account, you can make calls only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers Sandbox Numbers page.

Haven’t tried Plivo yet? Getting started is easy and only takes minutes. Sign up today.

Feb 28, 2022
5 mins

How to Build a Voice Survey Application the Low-Code Way Using PHLO

Plivo's SMS API and Voice API enables businesses to communicate with their customers at global scale. Sign up for free now.

PHLO
Node.Js SDK
Voice API
How To
Surveys

Plivo lets you automate voice surveys for use cases such as collecting feedback from customers and conducting polling on political issues. You can set up multiple levels of questions and walk users through different paths depending on the keys they press in response to your questions, and save the responses for analysis.

How it works

Broadcasting Call Flow

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time triggering a PHLO with Node.js, follow our instructions to set up a Node.js development environment.

Create the PHLO

To create a PHLO, visit the PHLO page of the Plivo console. If this is your first PHLO, the PHLO page will be empty.

  • Click Create New PHLO.
  • In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.

Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.

  • Click the Start node to open the Configuration tab to the right of the canvas, then enter the information to retrieve from the HTTP Request payload. For this example, enter From and To phone numbers and your business name.
  • Validate the configuration by clicking Validate. Every time you finish configuring a node, click Validate to check the syntax and save your changes.
  • From the list of components on the left side, drag and drop the Initiate Call component onto the canvas. This adds an Initiate Call node onto the canvas. When a component is placed on the canvas it becomes a node.
  • Draw a line to connect the Start node’s API Request trigger state to the Initiate Call node.
  • In the Configuration tab of the Initiate Call node, rename the node to Call_Customer. You can rename nodes as you like to improve your PHLO’s readability. To enter values for the From and To fields, start typing two curly brackets. PHLO will display a list of all available variables; choose the appropriate ones. When you use variables in a PHLO, the values are retrieved from the HTTP Request payload you defined in the Start node.
  • Next, drag and drop the IVR Menu component onto the canvas. Draw a line to connect the Initiate Call node‘s Answered trigger state to the IVR Menu node.
  • Click the IVR Menu node to open its Configuration tab. Rename the IVR Menu node Question_1. For this example, select 1 and 2 as allowed choices. In the Speak Text box, enter a message to play to the user that introduces the survey and states the choices they can respond with. If you like, you can also configure the Language and Voice fields for the message.
  • Repeat the process with another IVR Menu node. Rename it Question_2.

  • To daisy-chain to the second question after the user gives a valid response to question 1, connect the Question_1 node‘s 1 and 2 trigger states to the Question_2 node.
  • Configure the choices for Question_2 on its Configuration tab. Again, select 1 and 2 as allowed choices and enter a message to play to the user.
  • Drag and drop the Play Audio component onto the canvas. Draw a line to connect the Question_2 node‘s 1 and 2 trigger states to the Play Audio node.
  • In its Configuration tab, rename the node to Acknowledge_Participation. Enter a message of thanks to play to the user in the node‘s Speak Text box.
  • Drag and drop the HTTP Request component onto the canvas. Draw a line to connect the Acknowledge_Participation node‘s Prompt Completed trigger state to the HTTP Request node.
  • Rename the HTTP Request node Handle_Callback. Configure the node to post the survey results to a website. On its Configuration tab, enter key names answer1 and answer2. For their values, begin typing two curly brackets to view all available variables, then select Question_1.digits and Question_2.digits.
  • Give the PHLO a name by clicking in the upper left, then click Save.

Your PHLO is now ready to test.

Trigger the PHLO

You integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload — the set of parameters you pass to the PHLO. You can define a static payload by specifying values when you create the PHLO, or define a dynamic payload by passing values through parameters when you trigger the PHLO from your application.

With a static payload

When you configure values when creating the PHLO, they act as a static payload.

With Static Payload

Code

Create a file and paste the below code.

1
2
3
4
5
6
7
import plivo

phlo_id = "<phlo_id>"
phlo_client = plivo.phlo.RestClient("<auth_id>", "<auth_token>")
phlo = phlo_client.phlo.get(phlo_id)
response = phlo.run()
print(response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'rubygems'
require 'plivo'

include Plivo

AUTH_ID = '<auth_id>'
AUTH_TOKEN = '<auth_token>'

client = Phlo.new(AUTH_ID, AUTH_TOKEN)

# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
# then initialize client as:
# client = Phlo.new

begin
  phlo = client.phlo.get('<phlo_id>')
  response = phlo.run()
  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
var plivo = require('plivo');
var PhloClient = plivo.PhloClient;

var phloId = '<phlo_id>';
var phloClient = phlo = null;

phloClient = new PhloClient('<auth_id>', '<auth_token>');
phloClient.phlo(phloId).run().then(function(result) {
    console.log('Phlo run result', result);
}).catch(function(err) {
    console.error('Phlo run failed', err);
});
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("<auth_id>", "<auth_token>");

$phlo = $client->phlo->get("<phlo_id>");
try {
    $response = $phlo->run();
    print_r($response);
} catch (PlivoRestException $ex) {
    print_r($ex);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"fmt"
	"plivo-go"
)

// Initialize the following params with corresponding values to trigger resources
const authId = "<auth_id>"
const authToken = "<auth_token>"
const phloId = "<phlo_id>"

func main() {
	testPhloRunWithoutParams()
}

func testPhloRunWithoutParams() {
	phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	phloGet, err := phloClient.Phlos.Get(phloId)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	response, err := phloGet.Run(nil)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	fmt.Printf("Response: %#v\n", response)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using Plivo;

namespace test_PHLO
{
    class Program
    {
        public static void Main(string[] args)
        {
            var phloClient = new PhloApi("<auth_id>", "<auth_token>"); 
            var phloID = "<phlo_id>";
            var phlo = phloClient.Phlo.Get(phloID);   
            Console.WriteLine(phlo.Run());
        }
    }
}
1
2
3
4
curl --request POST \
  --user AUTH_ID:AUTH_TOKEN \
  --url 'https://phlorunner.plivo.com/v1/account/{auth_id}/phlo/{phlo_id}' \
  --header 'Content-Type: application/json'

Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console.

With a dynamic payload

To use dynamic values for the parameters, use Liquid templating parameters when you create the PHLO and pass the values from your code to the PHLO when you trigger it.

With Dynamic Payload

Code

Create a file and paste the below code.

1
2
3
4
5
6
7
import plivo

phlo_id = "<phlo_id>"
phlo_client = plivo.phlo.RestClient("<auth_id>", "<auth_token>")
phlo = phlo_client.phlo.get(phlo_id)
response = phlo.run()
print(response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'rubygems'
require 'plivo'

include Plivo

AUTH_ID = '<auth_id>'
AUTH_TOKEN = '<auth_token>'

client = Phlo.new(AUTH_ID, AUTH_TOKEN)

# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
# then initialize client as:
# client = Phlo.new

begin
  phlo = client.phlo.get('<phlo_id>')
  response = phlo.run()
  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
var plivo = require('plivo');
var PhloClient = plivo.PhloClient;

var phloId = '<phlo_id>';
var phloClient = phlo = null;

phloClient = new PhloClient('<auth_id>', '<auth_token>');
phloClient.phlo(phloId).run().then(function(result) {
    console.log('Phlo run result', result);
}).catch(function(err) {
    console.error('Phlo run failed', err);
});
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("<auth_id>", "<auth_token>");

$phlo = $client->phlo->get("<phlo_id>");
try {
    $response = $phlo->run();
    print_r($response);
} catch (PlivoRestException $ex) {
    print_r($ex);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import com.plivo.api.Plivo;
import com.plivo.api.PlivoClient;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.phlo.Phlo;
import java.io.IOException;

public class Example
{
    private static final String authId = "<auth_id>";
    private static final String authToken = "<auth_token>";
    private static PlivoClient client = new PlivoClient(authId, authToken);
    public static void main(String[] args) throws IOException, PlivoRestException
    {
        String phloId = "<phlo_id>";
        Plivo.init(authId, authToken);
        Phlo phlo = Phlo.getter(phloId).client(client).get();
        PhloUpdateResponse response = Phlo.updater(phloId).payload().run();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"fmt"
	"plivo-go"
)

// Initialize the following params with corresponding values to trigger resources
const authId = "<auth_id>"
const authToken = "<auth_token>"
const phloId = "<phlo_id>"

func main() {
	testPhloRunWithoutParams()
}

func testPhloRunWithoutParams() {
	phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	phloGet, err := phloClient.Phlos.Get(phloId)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	response, err := phloGet.Run(nil)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	fmt.Printf("Response: %#v\n", response)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using Plivo;

namespace test_PHLO
{
    class Program
    {
        public static void Main(string[] args)
        {
            var phloClient = new PhloApi("<auth_id>", "<auth_token>"); 
            var phloID = "<phlo_id>";
            var phlo = phloClient.Phlo.Get(phloID);   
            Console.WriteLine(phlo.Run());
        }
    }
}
1
2
3
4
curl --request POST \
  --user AUTH_ID:AUTH_TOKEN \
  --url 'https://phlorunner.plivo.com/v1/account/{auth_id}/phlo/{phlo_id}' \
  --header 'Content-Type: application/json'

Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).

Test

Save the file and run it.

Note: If you’re using a Plivo Trial account, you can make calls only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.

Haven’t tried Plivo yet? Getting started is easy and only takes minutes. Sign up today.

Feb 25, 2022
5 mins

How to Build a Voice Alerts Application the Low-Code Way Using PHLO

Plivo's SMS API and Voice API enables businesses to communicate with their customers at global scale. Sign up for free now.

PHLO
Voice API
How To
Alerts
Use Cases

You can make voice API calls to alert customers to critical issues that require immediate attention. You can play recorded audio when the call recipient answers or use text-to-speech. You can then take action based on a dialpad key they press in response. You can set different actions if the call is not answered, if the line is busy, or if you reach voicemail.

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time triggering a PHLO, follow our instructions to set up a development environment available in different languages.

Create the PHLO

To create a PHLO, visit the PHLO page of the Plivo console. If this is your first PHLO, the PHLO page will be empty.

  • Click Create New PHLO.
  • In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.
  • Click the Start node to open the Configuration tab to the right of the canvas, then enter the information to retrieve from the HTTP Request payload — in this case, from and to numbers and a database server name.
  • From the list of components on the left side, drag and drop the Initiate Call component onto the canvas. This adds an Initiate Call node onto the canvas. When a component is placed on the canvas it becomes a node.
  • Draw a line to connect the Start node’s API Request trigger state to the Initiate Call node.
  • In the Configuration tab of the Initiate Call node, give the node a meaningful name. To enter values for the From and To fields, start typing two curly brackets. PHLO will display a list of all available variables; choose the appropriate ones. When you use variables in a PHLO, the values are retrieved from the HTTP Request payload you defined in the Start node.
  • Validate the configuration by clicking Validate. Every time you finish configuring a node, click Validate to check the syntax and save your changes.
  • Next, create a node from the Play Audio component. Connect the Initiate Call node to the Play Audio node using the Answered trigger state.
  • Click the IVR Menu node to open its Configuration tab. Rename the node to Gather_Input. You can rename nodes as you like to improve your PHLO’s readability. For this example, select 1 and 2 as the allowed choices, and enter a message to play to the user in the Speak Text field. If you like, you can also configure the Language and Voice fields for the message.
  • Because we specified two allowed choices in the IVR menu, we need to drag and drop three Play Audio nodes onto the canvas — one for each option, plus one for invalid input. Rename the nodes Invalid_Input_Prompt, Resolved_Prompt, and Escalation_Prompt in their Configuration tabs, and enter appropriate messages in their Prompt fields.
  • From the Gather_Input node, connect the Wrong Input trigger state to the Invalid_Input_Prompt node.
  • From the Invalid_Input_Prompt node, connect the Prompt Completed trigger state back to the Gather_Input node. This sends the user back to the IVR menu if they press an incorrect option, or if they don‘t press any key.
  • From the Gather_Input node, connect the 1 and 2 trigger states to the Resolved_Prompt and Escalation_Prompt nodes.
  • Configure all three Play Audio nodes to each play a relevant message to the user. Audio playback can either be static or dynamic or a combination of the two; for example, you could specify in the Speak Text field “Your status is,” followed by a variable to include the dynamic text. You can bring up a list of available variables by typing two curly brackets in the Speak Text field.
  • Drag and drop the Initiate Call component onto the canvas and rename the node to Escalation_Call.
  • Draw a line to connect the Prompt Completed trigger state of the Escalation_Prompt node to the Escalation_Call node. This triggers a call to another phone number and announces the alert. You can set up any number of escalation numbers by creating similar nodes for each phone number.
  • Draw a line to connect the Answered trigger state of the Escalation_Call node back to the Gather Input node. This will play the same prompt to the user after the original escalation call is answered and completed and give the user another chance to either resolve the call or escalate it.
  • After you complete and validate all the node configurations, give the PHLO a name by clicking in the upper left, then click Save.

Your completed PHLO should look like this:

Voice Alert

Your PHLO is now ready to test.

Trigger the PHLO

You integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload — the set of parameters you pass to the PHLO. You can define a static payload by specifying values when you create the PHLO, or define a dynamic payload by passing values through parameters when you trigger the PHLO from your application.

With a static payload

When you configure values when creating the PHLO, they act as a static payload.

With Static Payload

Code

Create a file and paste the below code.

1
2
3
4
5
6
7
import plivo

phlo_id = "<phlo_id>"
phlo_client = plivo.phlo.RestClient("<auth_id>", "<auth_token>")
phlo = phlo_client.phlo.get(phlo_id)
response = phlo.run()
print(response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'rubygems'
require 'plivo'

include Plivo

AUTH_ID = '<auth_id>'
AUTH_TOKEN = '<auth_token>'

client = Phlo.new(AUTH_ID, AUTH_TOKEN)

# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
# then initialize client as:
# client = Phlo.new

begin
  phlo = client.phlo.get('<phlo_id>')
  response = phlo.run()
  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
var plivo = require('plivo');
var PhloClient = plivo.PhloClient;

var phloId = '<phlo_id>';
var phloClient = phlo = null;

phloClient = new PhloClient('<auth_id>', '<auth_token>');
phloClient.phlo(phloId).run().then(function(result) {
    console.log('Phlo run result', result);
}).catch(function(err) {
    console.error('Phlo run failed', err);
});
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("<auth_id>", "<auth_token>");

$phlo = $client->phlo->get("<phlo_id>");
try {
    $response = $phlo->run();
    print_r($response);
} catch (PlivoRestException $ex) {
    print_r($ex);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import com.plivo.api.Plivo;
import com.plivo.api.PlivoClient;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.phlo.Phlo;
import java.io.IOException;

public class Example
{
    private static final String authId = "<auth_id>";
    private static final String authToken = "<auth_token>";
    private static PlivoClient client = new PlivoClient(authId, authToken);
    public static void main(String[] args) throws IOException, PlivoRestException
    {
        String phloId = "<phlo_id>";
        Plivo.init(authId, authToken);
        Phlo phlo = Phlo.getter(phloId).client(client).get();
        PhloUpdateResponse response = Phlo.updater(phloId).payload().run();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"fmt"
	"plivo-go"
)

// Initialize the following params with corresponding values to trigger resources
const authId = "<auth_id>"
const authToken = "<auth_token>"
const phloId = "<phlo_id>"

func main() {
	testPhloRunWithoutParams()
}

func testPhloRunWithoutParams() {
	phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	phloGet, err := phloClient.Phlos.Get(phloId)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	response, err := phloGet.Run(nil)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	fmt.Printf("Response: %#v\n", response)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using Plivo;

namespace test_PHLO
{
    class Program
    {
        public static void Main(string[] args)
        {
            var phloClient = new PhloApi("<auth_id>", "<auth_token>"); 
            var phloID = "<phlo_id>";
            var phlo = phloClient.Phlo.Get(phloID);   
            Console.WriteLine(phlo.Run());
        }
    }
}
1
2
3
4
curl --request POST \
  --user AUTH_ID:AUTH_TOKEN \
  --url 'https://phlorunner.plivo.com/v1/account/{auth_id}/phlo/{phlo_id}' \
  --header 'Content-Type: application/json'

Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console.

With a dynamic payload

To use dynamic values for the parameters, use Liquid templating parameters when you create the PHLO and pass the values from your code to the PHLO when you trigger it.

With Dynamic Payload

Code

Create a file and paste the below code.

1
2
3
4
5
6
7
8
9
10
import plivo

auth_id = '<auth_id>'
auth_token = '<auth_token>'
phlo_id = '<phlo_id>'
payload = {"From" : "<caller_id>","To" : "<destination_number>"}
phlo_client = plivo.phlo.RestClient(auth_id=auth_id, auth_token=auth_token)
phlo = phlo_client.phlo.get(phlo_id)
response = phlo.run(**payload)
print (response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'rubygems'
require 'plivo'

include Plivo

AUTH_ID = '<auth_id>'
AUTH_TOKEN = '<auth_token>'

client = Phlo.new(AUTH_ID, AUTH_TOKEN)

# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
# then initialize client as:
# client = Phlo.new

begin
  phlo = client.phlo.get('<phlo_id>')
  #parameters set in PHLO - params
  params = {
     From: '<caller_id>',
     To: '<destination_number>',
  }
  response = phlo.run(params)
  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var plivo = require('plivo');
var PhloClient = plivo.PhloClient;

var authId = '<auth_id>';
var authToken = '<auth_token>';
var phloId = '<phlo_id>';
var phloClient = phlo = null;

var payload = {
    From: '<caller_id>',
    To: '<destination_number>',
}
phloClient = new PhloClient(authId, authToken);
phloClient.phlo(phloId).run(payload).then(function (result) {
    console.log('Phlo run result', result);
}).catch(function (err) {
    console.error('Phlo run failed', err);
});
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("<auth_id>", "<auth_token>");

$phlo = $client->phlo->get("<phlo_id>");
try {
    $response = $phlo->run(["From" => "<caller_id>", "To" => "<destination_number>"]);
    print_r($response);
} catch (PlivoRestException $ex) {
    print_r($ex);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import com.plivo.api.Plivo;
import com.plivo.api.PlivoClient;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.phlo.Phlo;
import java.io.IOException;

public class Example
{
    private static final String authId = "<auth_id>";
    private static final String authToken = "<auth_token>";
    private static PlivoClient client = new PlivoClient(authId, authToken);
    public static void main(String[] args) throws IOException, PlivoRestException
    {
        String phloId = "<phlo_id>";
        Plivo.init(authId, authToken);
        Phlo phlo = Phlo.getter(phloId).client(client).get();
        Map<String, Object> payload = new HashMap<>();
        payload.put("From", "<caller_id>");
        payload.put("To", "<destination_number>");
        PhloUpdateResponse response = Phlo.updater(phloId).payload(payload).run();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"fmt"
	"plivo-go"
)

// Initialize these parameters with corresponding values to trigger resources
const authId = "<auth_id>"
const authToken = "<auth_token>"
const phloId = "<phlo_id>"

func main() {
	testPhloRunWithParams()
}

func testPhloRunWithParams() {
	phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	phloGet, err := phloClient.Phlos.Get(phloId)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	//pass corresponding from and to values
	type params map[string]interface{}
	response, err := phloGet.Run(params{
		"From": "<caller_id>",
		"To":   "<destination_number>",
	})

	if err != nil {
		println(err)
	}
	fmt.Printf("Response: %#v\n", response)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
using Plivo;

namespace test_PHLO
{
    class Program
    {
        public static void Main(string[] args)
        {
            var phloClient = new PhloApi("<auth_id>", "<auth_token>");
            var phloID = "<phlo_id>";
            var phlo = phloClient.Phlo.Get(phloID); 
            var data = new Dictionary<string, object>
            {
                { "From", "<caller_id>" },
                { "To", "<destination_number>" }

            };  
            Console.WriteLine(phlo.Run(data));
        }
    }
}
1
2
3
4
5
curl --request POST \
  --user AUTH_ID:AUTH_TOKEN \
  --url 'https://phlorunner.plivo.com/v1/account/{auth_id}/phlo/{phlo_id}' \
  --header 'Content-Type: application/json' \
  --data '{"from": "<caller_id>","to": "<destination_number>"}'

Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).

Test

Save the file and run it.

Note: If you’re using a Plivo Trial account, you can make calls only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.

Haven’t tried Plivo yet? Getting started is easy and only takes minutes. Sign up today.

Feb 22, 2022
5 mins

How to Build a Voice Notifications Application the Low-Code Way Using PHLO

Plivo's SMS API and Voice API enables businesses to communicate with their customers at global scale. Sign up for free now.

PHLO
Voice API
How To
Notifications
Use Cases

You can play recorded audio when a call recipient answers or use text-to-speech, as we show here, combining static text with dynamic information that Plivo gets from a variable. You can create and deploy a PHLO to send voice notifications with a few clicks on the PHLO canvas.

How it works

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time triggering a PHLO, follow our instructions to set up a development environment available in different languages.

Create the PHLO

To create a PHLO, visit the PHLO page of the Plivo console. If this is your first PHLO, the PHLO page will be empty.

  • Click Create New PHLO.
  • In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.
  • Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.
  • Click the Start node to open the Configurations tab, then enter the information to retrieve from the HTTP Request payload — in this case, the From and To numbers for the call, and an item number.
  • From the list of components on the left side, drag and drop the Initiate Call component onto the canvas. This adds an Initiate Call node onto the canvas. When a component is placed on the canvas it becomes a node.
  • Draw a line to connect the Start node’s API Request trigger state to the Initiate Call node.
  • In the Configuration tab of the Initiate Call node, give the node a name. To enter values for the From and To fields, enter two curly brackets to view all available variables, and choose the appropriate ones. The values for the numbers will be retrieved from the HTTP Request payload you defined in the Start node.
  • Validate the configuration by clicking Validate. Do the same for each node as you go along.
  • Next, create a node from the Play Audio component. Connect the Initiate Call node to the Play Audio node using the Answered trigger state.
  • Configure the Play Audio node to play a message to the user by entering text in the Speak Text box in the Prompt section of the Configuration pane.
  • Audio playback can either be static or dynamic. You define a static payload by specifying values when you create the PHLO, and a dynamic payload by passing values through Liquid templating parameters when you trigger the PHLO from your application.
  • On the Play Audio Configuration tab, enter a static message (for example, “Your order has been successfully placed”) in the Speak Text field, with a variable to include the dynamic text. Enter two curly brackets to view all available variables. Choose the item number you defined in the Start node configuration tab.
  • After you complete and validate the node configurations, give the PHLO a name by clicking in the upper left, then click Save.

Your completed PHLO should look like this:

Voice Notification

Your PHLO is now ready to test.

Trigger the PHLO

You integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload — the set of parameters you pass to the PHLO. You can define a static payload by specifying values when you create the PHLO, or define a dynamic payload by passing values through parameters when you trigger the PHLO from your application.

With a static payload

When you configure values when creating the PHLO, they act as a static payload.

With Static Payload

Code

Create a file and paste the below code.

Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console.

With a dynamic payload

To use dynamic values for the parameters, use Liquid templating parameters when you create the PHLO and pass the values from your code to the PHLO when you trigger it.

With Dynamic Payload

Code

Create a file and paste the below code.

1
2
3
4
5
6
7
import plivo

phlo_id = "<phlo_id>"
phlo_client = plivo.phlo.RestClient("<auth_id>", "<auth_token>")
phlo = phlo_client.phlo.get(phlo_id)
response = phlo.run()
print(response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'rubygems'
require 'plivo'

include Plivo

AUTH_ID = '<auth_id>'
AUTH_TOKEN = '<auth_token>'

client = Phlo.new(AUTH_ID, AUTH_TOKEN)

# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
# then initialize client as:
# client = Phlo.new

begin
  phlo = client.phlo.get('<phlo_id>')
  response = phlo.run()
  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
var plivo = require('plivo');
var PhloClient = plivo.PhloClient;

var phloId = '<phlo_id>';
var phloClient = phlo = null;

phloClient = new PhloClient('<auth_id>', '<auth_token>');
phloClient.phlo(phloId).run().then(function(result) {
    console.log('Phlo run result', result);
}).catch(function(err) {
    console.error('Phlo run failed', err);
});
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("<auth_id>", "<auth_token>");

$phlo = $client->phlo->get("<phlo_id>");
try {
    $response = $phlo->run();
    print_r($response);
} catch (PlivoRestException $ex) {
    print_r($ex);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import com.plivo.api.Plivo;
import com.plivo.api.PlivoClient;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.phlo.Phlo;
import java.io.IOException;

public class Example
{
    private static final String authId = "<auth_id>";
    private static final String authToken = "<auth_token>";
    private static PlivoClient client = new PlivoClient(authId, authToken);
    public static void main(String[] args) throws IOException, PlivoRestException
    {
        String phloId = "<phlo_id>";
        Plivo.init(authId, authToken);
        Phlo phlo = Phlo.getter(phloId).client(client).get();
        PhloUpdateResponse response = Phlo.updater(phloId).payload().run();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"fmt"
	"plivo-go"
)

// Initialize the following params with corresponding values to trigger resources
const authId = "<auth_id>"
const authToken = "<auth_token>"
const phloId = "<phlo_id>"

func main() {
	testPhloRunWithoutParams()
}

func testPhloRunWithoutParams() {
	phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	phloGet, err := phloClient.Phlos.Get(phloId)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	response, err := phloGet.Run(nil)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	fmt.Printf("Response: %#v\n", response)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using Plivo;

namespace test_PHLO
{
    class Program
    {
        public static void Main(string[] args)
        {
            var phloClient = new PhloApi("<auth_id>", "<auth_token>"); 
            var phloID = "<phlo_id>";
            var phlo = phloClient.Phlo.Get(phloID);   
            Console.WriteLine(phlo.Run());
        }
    }
}
1
2
3
4
curl --request POST \
  --user AUTH_ID:AUTH_TOKEN \
  --url 'https://phlorunner.plivo.com/v1/account/{auth_id}/phlo/{phlo_id}' \
  --header 'Content-Type: application/json'

Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).

Test

Save the file and run it.

Note: If you’re using a Plivo Trial account, you can make calls only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.

Haven’t tried Plivo yet? Getting started is easy and only takes minutes. Sign up today.

Feb 16, 2022
5 mins

How to Build a Voicemail Application the No-Code Way Using PHLO

Plivo's SMS API and Voice API enables businesses to communicate with their customers at global scale. Sign up for free now.

PHLO
Voice API
How To
Voicemail
Use Cases

You can use voicemail to capture a caller’s message if a call recipient is unavailable. You can create and deploy a PHLO workflow to implement voicemail with a few clicks on the PHLO canvas.

Voicemail call flow

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. To receive incoming calls, you must have a voice-enabled Plivo phone number. You can rent numbers from the Numbers page of the Plivo console, or by using the Numbers API.

Create the PHLO

To create a PHLO, visit the PHLO page of the Plivo console. If this is your first PHLO, the PHLO page will be empty.

  • Click CREATE NEW PHLO.
  • In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.
  • Click the Start node to open the Configuration tab, then enter from and to as keys in the API Request section. To keep the PHLO dynamic, don‘t enter values for the variables.
  • Once you’ve configured the node, save the configuration by clicking Validate. Do the same for each node as you go along.
  • From the list of components on the left side, drag and drop the Record Audio component onto the canvas. When a component is placed on the canvas it becomes a node. In its Configuration tab, give the node a descriptive name, such as Voicemail_Message, and enter text for a message you want to play to callers.
  • Draw a line to connect the Start node‘s Incoming Call trigger state to the Record Audio node.
  • Once a message is recorded, send the URL of the recording to a responsible party. To do that, drag and drop the Send Message component into the canvas, and rename it Send_Recording_URL.
  • In its Configuration tab, enter variables for the From and To fields. Enter two curly brackets to view all available variables, and choose the appropriate ones. PHLO will get the number from the key/value pairs set in the Start node. In the Message field, enter a message that provides context for the voicemail recipient. The message can be static or dynamic or a combination of the two.
  • Give the PHLO a name by clicking in the upper left, then click Save.

Your complete PHLO should look like this.

Voicemail

Assign the PHLO to a Plivo number

Once you‘ve created and configured your PHLO, assign it to a Plivo number.

  • On the Numbers page of the console, under Your Numbers, click the phone number you want to use for the PHLO.
  • In the Number Configuration box, select PHLO from the Application Type drop-down.
  • From the PHLO Name drop-down, select the PHLO you want to use with the phone number, then click Update Number.
Assign PHLO to a Plivo Number

Test

You can now call your Plivo phone number and see how the voicemail PHLO works.

For more information about creating a PHLO application, see the PHLO Getting Started guide. For information on components and their variables, see the PHLO Components Library.

Haven’t tried Plivo yet? Getting started is easy and only takes minutes. Sign up today.

Feb 14, 2022
5 mins

How to Build an Inbound SIP Trunk for Voice Origination Using PHLO

Learn how to build an inbound SIP trunk for voice origination to enhance your business communications efficiently.

PHLO
SIP Trunking
How To
Use Cases

Plivo’s PHLO visual workflow builder lets you quickly create and configure a SIP trunk call forwarding system for your business. You can migrate your existing SIP trunk hosted voice application to PHLO, which then forwards your Plivo number’s incoming calls to an IP PBX and SIP endpoint.

Configure your inbound SIP trunk

Plivo provides SIP trunk configuration instructions for the most popular SIP trunking platforms, including Freeswitch, Asterisk, FreePBX, 3CX, and FusionPBX.

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. To receive incoming calls, you must have a voice-enabled Plivo phone number. You can rent numbers from the Numbers page of the Plivo console, or by using the Numbers API.

Create a PHLO to forward inbound calls

To forward an incoming call, you can create and deploy a PHLO with a few clicks on the PHLO canvas.

Create a PHLO
  • On the side navigation bar, click PHLO. The PHLO page will appear and display your existing PHLOs, if any exist. If this is your first PHLO, then the PHLO page will be empty.
  • Click Create New PHLO to build a new PHLO.
  • In the Choose your use case window, choose the Call Forwarding use case. The PHLO canvas will appear with a prebuilt template for the Call Forwarding use case.
  • Configure the Call Forward node.
  • From field: This will be already configured with . It’s the caller ID to display to the recipient of the forwarded call.
  • To field: List of recipients to forward the incoming call and to bridge into the active call. The list can contain IP PBXes and SIP endpoints separated by a comma:

    • sip:1NPANXXYYYY@sip.example.com
    • sip:phonenumber@192.0.0.1
    • sip:sipendpoint@phone.plivo.com

    Note: You must choose sequential for call forwarding configuration setting so that it will be dialed sequentially on failover.

  • Once you’ve configured the node, click Validate to save the configurations.
  • After you complete the configuration, provide a name for your PHLO and click Save.

Assign the PHLO to a Plivo number to forward incoming calls

Once you’ve created and configured your PHLO, assign your PHLO to a Plivo number.

  1. Log in to the Plivo console.
  2. On the Product Navigation bar, click Phone Numbers.
  3. On the Numbers page, under Your Numbers, click the phone number you want to use for the PHLO.
  4. In the Number Configuration window, select PHLO from the Application Type list.
  5. From the PHLO Name list, select the PHLO you want to use with the phone number, and then click Update Number.
Assign a Phone Number

Test

You can now make a call to your Plivo phone number and see how the inbound call is forwarded to the list of IP PBXes and endpoint 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.

Haven’t tried Plivo yet? Getting started is easy and only takes minutes. Sign up today.

Feb 11, 2022
5 mins

How to Build an SMS Survey Application the Low-Code Way Using PHLO

Plivo's SMS API and Voice API enables businesses to communicate with their customers at global scale. Sign up for free now.

PHLO
SMS API
How To
Surveys
Use Cases

You can build SMS surveys easily by using our PHLO visual workflow builder.

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time triggering a PHLO with .NET, follow our instructions to set up a .NET development environment.

Create the PHLO

To create a PHLO, visit the PHLO page of the Plivo console. If this is your first PHLO, the PHLO page will be empty.

  • Click Create New PHLO.
  • In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.
  • If you plan to use a dynamic payload — passing values through parameters when you trigger the PHLO from your application — click on the Start node to open the Configuration pane. Under API Request, enter key names for the variables you want use in your payload — From, To, and Message fields.
  • Once you’ve configured the node, click Validate to save the configuration.
  • From the list of components on the left-hand side, drag and drop the Send Message component onto the canvas. When a component is placed on the canvas it becomes a node.
  • Draw a line to connect the Start node’s API Request trigger state to the Send Message node.
  • In the Configuration pane at the right of the canvas, configure the Send Message node with a sender ID in the From field. Enter the destination numbers you wish to send a message to in the To field. Put your message in the Text field.Note: You can define a static payload by specifying values when you create the PHLO, or define a dynamic payload by passing values through Liquid templating parameters when you trigger the PHLO from your application.
  • Once you’ve configured the node, click Validate to save the configuration.
  • From the list of components on the left-hand side, drag and drop the Branch component onto the canvas.
  • Draw a line to connect the Start node’s Incoming Message trigger state to the Branch node.
  • In the Configuration pane at the right of the canvas, configure the Branch node. Rename the node to Handle_Reply. For Variable to compare, enter two curly braces to view all available variables, then select Start.message.msg.
  • Click the pencil icon and name the first condition Satisfied. Leave the Operation “is equal to” and enter a value of 1.
  • Add a second condition. Name it Not Satisfied and enter a value of 2.
  • Once you’ve configured the node, click Validate to save the configuration.
  • Drag two Send Message nodes onto the canvas. Draw lines to connect them to the Handle_Reply node using the Satisfied and Not Satisfied trigger states.
  • In the Configuration pane for each of the Send Message nodes, specify the From and To keys you configured in the Start node. Enter two curly brackets to display a list of all available variables. In the Message field, you can enter a static message, or combine static text with a variable that includes dynamic text if you specified the variable as a key in the Start node configuration pane.
  • Rename the nodes Reply_Satisfied and Reply_NotSatisfied.
  • Once you’ve configured the nodes, click Validate to save their configurations.
  • From the list of components on the left-hand side, drag and drop the HTTP Request component onto the canvas. Draw four lines to connect the Sent and Failed trigger states of both the Reply_Satisfied and Reply_NotSatisfied nodes to the HTTP Request node.
  • In the Configuration pane for the HTTP Request node, rename the node to Handle_Callback. Enter URL to make the request to. The default method used is GET, but you can click on the box to choose POST, PUT, or DELETE instead. Specify Headers, Auth, Params, and Body values on their respective tabs as necessary.
  • Once you’ve configured the node, click Validate to save the configuration.

After you complete the configuration, give the PHLO a name by clicking in the upper left, then click Save.

Your complete PHLO should look like this:

Your PHLO is now ready to test.

Trigger the PHLO

You integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload — the set of parameters you pass to the PHLO. You can define a static payload by specifying values when you create the PHLO, or define a dynamic payload by passing values through parameters when you trigger the PHLO from your application.

In either case, you need your Auth ID and Auth Token, which you can get from the overview page of the Plivo console.

AUTHID

You also need the PHLO ID, which you can copy from the PHLO list page.

PHLO List

With a static payload

When you configure values when creating the PHLO, they act as a static payload.

With Static Payload

Code

Create a file and paste the below code.

1
2
3
4
5
6
7
import plivo

phlo_id = "<phlo_id>"
phlo_client = plivo.phlo.RestClient("<auth_id>", "<auth_token>")
phlo = phlo_client.phlo.get(phlo_id)
response = phlo.run()
print(response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'rubygems'
require 'plivo'

include Plivo

AUTH_ID = '<auth_id>'
AUTH_TOKEN = '<auth_token>'

client = Phlo.new(AUTH_ID, AUTH_TOKEN)

# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
# then initialize client as:
# client = Phlo.new

begin
  phlo = client.phlo.get('<phlo_id>')
  response = phlo.run()
  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
var plivo = require('plivo');
var PhloClient = plivo.PhloClient;

var phloId = '<phlo_id>';
var phloClient = phlo = null;

phloClient = new PhloClient('<auth_id>', '<auth_token>');
phloClient.phlo(phloId).run().then(function(result) {
    console.log('Phlo run result', result);
}).catch(function(err) {
    console.error('Phlo run failed', err);
});
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("<auth_id>", "<auth_token>");

$phlo = $client->phlo->get("<phlo_id>");
try {
    $response = $phlo->run();
    print_r($response);
} catch (PlivoRestException $ex) {
    print_r($ex);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import com.plivo.api.Plivo;
import com.plivo.api.PlivoClient;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.phlo.Phlo;
import java.io.IOException;

public class Example
{
    private static final String authId = "<auth_id>";
    private static final String authToken = "<auth_token>";
    private static PlivoClient client = new PlivoClient(authId, authToken);
    public static void main(String[] args) throws IOException, PlivoRestException
    {
        String phloId = "<phlo_id>";
        Plivo.init(authId, authToken);
        Phlo phlo = Phlo.getter(phloId).client(client).get();
        PhloUpdateResponse response = Phlo.updater(phloId).payload().run();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"fmt"
	"plivo-go"
)

// Initialize the following params with corresponding values to trigger resources
const authId = "<auth_id>"
const authToken = "<auth_token>"
const phloId = "<phlo_id>"

func main() {
	testPhloRunWithoutParams()
}

func testPhloRunWithoutParams() {
	phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	phloGet, err := phloClient.Phlos.Get(phloId)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	response, err := phloGet.Run(nil)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	fmt.Printf("Response: %#v\n", response)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using Plivo;

namespace test_PHLO
{
    class Program
    {
        public static void Main(string[] args)
        {
            var phloClient = new PhloApi("<auth_id>", "<auth_token>"); 
            var phloID = "<phlo_id>";
            var phlo = phloClient.Phlo.Get(phloID);   
            Console.WriteLine(phlo.Run());
        }
    }
}
1
2
3
4
curl --request POST \
  --user AUTH_ID:AUTH_TOKEN \
  --url 'https://phlorunner.plivo.com/v1/account/{auth_id}/phlo/{phlo_id}' \
  --header 'Content-Type: application/json'

Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console.

With a dynamic payload

To use dynamic values for the parameters, use Liquid templating parameters when you create the PHLO …

With Dynamic Payload

… and pass the values from your code when you trigger it.

With Dynamic Payload

Code

Create a file and paste the below code.

1
2
3
4
5
6
7
8
9
10
import plivo

auth_id = '<auth_id>'
auth_token = '<auth_token>'
phlo_id = '<phlo_id>'
payload = {"From" : "<caller_id>","To" : "<destination_number>"}
phlo_client = plivo.phlo.RestClient(auth_id=auth_id, auth_token=auth_token)
phlo = phlo_client.phlo.get(phlo_id)
response = phlo.run(**payload)
print (response)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'rubygems'
require 'plivo'

include Plivo

AUTH_ID = '<auth_id>'
AUTH_TOKEN = '<auth_token>'

client = Phlo.new(AUTH_ID, AUTH_TOKEN)

# if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
# then initialize client as:
# client = Phlo.new

begin
  phlo = client.phlo.get('<phlo_id>')
  #parameters set in PHLO - params
  params = {
     From: '<caller_id>',
     To: '<destination_number>',
  }
  response = phlo.run(params)
  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var plivo = require('plivo');
var PhloClient = plivo.PhloClient;

var authId = '<auth_id>';
var authToken = '<auth_token>';
var phloId = '<phlo_id>';
var phloClient = phlo = null;

var payload = {
    From: '<caller_id>',
    To: '<destination_number>',
}
phloClient = new PhloClient(authId, authToken);
phloClient.phlo(phloId).run(payload).then(function (result) {
    console.log('Phlo run result', result);
}).catch(function (err) {
    console.error('Phlo run failed', err);
});
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("<auth_id>", "<auth_token>");

$phlo = $client->phlo->get("<phlo_id>");
try {
    $response = $phlo->run(["From" => "<caller_id>", "To" => "<destination_number>"]);
    print_r($response);
} catch (PlivoRestException $ex) {
    print_r($ex);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import com.plivo.api.Plivo;
import com.plivo.api.PlivoClient;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.phlo.Phlo;
import java.io.IOException;

public class Example
{
    private static final String authId = "<auth_id>";
    private static final String authToken = "<auth_token>";
    private static PlivoClient client = new PlivoClient(authId, authToken);
    public static void main(String[] args) throws IOException, PlivoRestException
    {
        String phloId = "<phlo_id>";
        Plivo.init(authId, authToken);
        Phlo phlo = Phlo.getter(phloId).client(client).get();
        Map<String, Object> payload = new HashMap<>();
        payload.put("From", "<caller_id>");
        payload.put("To", "<destination_number>");
        PhloUpdateResponse response = Phlo.updater(phloId).payload(payload).run();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"fmt"
	"plivo-go"
)

// Initialize these parameters with corresponding values to trigger resources
const authId = "<auth_id>"
const authToken = "<auth_token>"
const phloId = "<phlo_id>"

func main() {
	testPhloRunWithParams()
}

func testPhloRunWithParams() {
	phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	phloGet, err := phloClient.Phlos.Get(phloId)
	if err != nil {
		fmt.Print("Error", err.Error())
		return
	}
	//pass corresponding from and to values
	type params map[string]interface{}
	response, err := phloGet.Run(params{
		"From": "<caller_id>",
		"To":   "<destination_number>",
	})

	if err != nil {
		println(err)
	}
	fmt.Printf("Response: %#v\n", response)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
using Plivo;

namespace test_PHLO
{
    class Program
    {
        public static void Main(string[] args)
        {
            var phloClient = new PhloApi("<auth_id>", "<auth_token>");
            var phloID = "<phlo_id>";
            var phlo = phloClient.Phlo.Get(phloID); 
            var data = new Dictionary<string, object>
            {
                { "From", "<caller_id>" },
                { "To", "<destination_number>" }

            };  
            Console.WriteLine(phlo.Run(data));
        }
    }
}
1
2
3
4
5
curl --request POST \
  --user AUTH_ID:AUTH_TOKEN \
  --url 'https://phlorunner.plivo.com/v1/account/{auth_id}/phlo/{phlo_id}' \
  --header 'Content-Type: application/json' \
  --data '{"from": "<caller_id>","to": "<destination_number>"}'

Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phlo_id placeholder with your PHLO ID from the Plivo console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).

Test

Save the file and run it.

Note: If you’re using a Plivo Trial account, you can send SMS messages only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.

For more information about creating a PHLO application, see the PHLO Getting Started guide. For information on components and their variables, see the PHLO Components Library.

Haven’t tried Plivo yet? Getting started is easy and only takes minutes. Sign up today.

Feb 9, 2022
5 mins

How to Build a 2FA Application the Low-Code Way Using PHLO

Plivo's SMS API and Voice API enables businesses to communicate with their customers at global scale. Sign up for free now.

PHLO
Node.Js SDK
SMS API
How To
2FA

Two-factor authentication (2FA) protects organizations and individuals from unauthorized data access by requiring a level of authentication beyond username and password, to provide added security in the event that those credentials are compromised. One of the simplest ways to institute 2FA types is by sending a one-time password (OTP) sent through a separate communication channel — namely, SMS messaging.

Plivo makes it easy to add 2FA via OTP delivered over SMS to your applications. Whether your applications are coded in Python, Ruby, Node.js, PHP, or C#, we’ve got you covered with language-specific SDKs.

You can create and deploy a PHLO to handle 2FA with a few clicks on the PHLO canvas and trigger it with a few lines of code.

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time triggering a PHLO with Node.js, follow our instructions to set up a Node.js development environment.

Create the PHLO

Plivo provides a prototype for 2FA; all you have to do is select the PHLO and give it a friendly name.

Set up the demo application locally

Once you‘ve created the PHLO, download and modify the code to trigger it which is available in 5 different languages which are Python, Ruby, Node.js, PHP, or C#.

Update the config file

Edit the config file. Replace the auth placeholders with your authentication credentials from the Plivo console. Enter your PHLO ID, which you can find on the Plivo console. Replace the phone number placeholder with an actual phone number in E.164 format (for example, +12025551234).

Configuration file

Trigger PHLO

Send SMS and make a call

          def send_verification_code_phlo(self,dst_number,code,mode):
          payload = {
              "from": self.app_number,
              "to": dst_number,
              "otp": code,
              "mode": mode,
          }
          try:
              phlo = self.client_phlo.phlo.get(self.phlo_id)
              response = phlo.run(**payload)
              return response
          except exceptions as e:
              print(e)
              return ("Error encountered", 400)
        

Verify the OTP

        @app.route("/checkcode/<number>/<code>")
        def check_code(number, code):
            """
            check_code(number, code) accepts a number and the code entered by the user and
            tells if the code entered for that number is correct or not
            """

            original_code = current_app.redis.get("number:%s:code" % number)
            if original_code == code:  # verification successful, delete the code
                current_app.redis.delete("number:%s:code" % number)
                return (jsonify({"status": "success", "message": "codes match, number verified"}),200,)
            elif original_code != code:
                return (
                    jsonify(
                        {
                            "status": "rejected",
                            "message": "codes do not match, number not verified",
                        }
                    ),
                    404,
                )
            else:
                return (jsonify({"status": "failed", "message": "number not found"}), 500)
        

The finished application should look like this.

Simple and reliable

Edit the sample application to see how simple it was to code. Our simple APIs work in tandem with our comprehensive global network. Plivo’s premium direct routes guarantee highest possible delivery rates and the shortest possible delivery times for your 2FA SMS and voice messages. See for yourself — sign up for a free trial account.

Feb 3, 2022
5 mins

How to Build a Conference Application the No-Code Way Using PHLO

Plivo's SMS API and Voice API enables businesses to communicate with their customers at global scale. Sign up for free now.

PHLO
Voice API
How To
Conference

You can create and deploy a workflow to implement conference calling with a few clicks on the PHLO canvas.

Prerequisites

To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. To receive incoming calls, you must have a voice-enabled Plivo phone number. You can rent numbers from the Numbers page of the Plivo console, or by using the Numbers API.

Create the PHLO

To create a PHLO, visit the PHLO page of the Plivo console. If this is your first PHLO, the PHLO page will be empty.

  • Click CREATE NEW PHLO.
  • In the Choose your use case pop-up, click Build my own. The PHLO canvas will appear with the Start node.Note: The Start node is the starting point of any PHLO. It lets you trigger a PHLO to start upon one of three actions: incoming SMS message, incoming call, or API request.
  • From the list of components on the left side, drag and drop the Conference Bridge component onto the canvas. When a component is placed on the canvas it becomes a node.
  • Draw a line to connect the Start node‘s Incoming Call trigger state to the Conference Bridge node.
  • In the Configuration tab at the right of the canvas, enter a Conference ID for your conference. You can also add an announcement message to greet callers, and configure the hold music.
  • Once you’ve configured the node, click Validate to save the configuration.
  • Give the PHLO a name by clicking in the upper left, then click Save.

Your complete PHLO should look like this.

Conference without Pin

Assign the PHLO to a Plivo number

Once you’ve created and configured your PHLO, assign it to a Plivo number.

  • On the Numbers page of the console, under Your Numbers, click the phone number you want to use for the PHLO.
  • In the Number Configuration box, select PHLO from the Application Type drop-down.
  • From the PHLO Name drop-down, select the PHLO you want to use with the phone number, then click Update Number.
Assign PHLO to a Plivo Number

Test

You can now call to your Plivo phone number and see how callers are added to a conference call.

For more information about creating a PHLO application, see the PHLO Getting Started guide. For information on components and their variables, see the PHLO Components Library.

Haven’t tried Plivo yet? Getting started is easy and only takes minutes. Sign up today.