Using this guide, you can set up a development environment in five minutes to trigger a PHLO.
To get started, install Ruby, Rails, and Plivo’s Ruby SDK. You can check whether you have Ruby installed by running ruby --version
in a terminal window. If you don’t have it, macOS and Linux users can install it using homebrew, and Windows users can use RubyInstaller.
To install Rails, run
gem install rails
Auto-generate code for a new Rails project with the command
rails new plivotest
This command creates a directory named plivotest with the necessary folders and files for development.
Add the Plivo Ruby SDK by editing the Gemfile and adding the line
gem 'plivo', '~> 4.16.0'
To install the Plivo-Ruby gem into the bundle, run
bundle install
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.
Now you can create a file in the project directory and execute code to trigger any Plivo API. Change to the newly created plivotest project directory and run this command to create a Rails controller for outbound calls.
rails generate controller Plivo voice
This command generates a controller named plivo_controller in the app/controllers/ directory and a view in app/views/plivo. You can delete the view — we don’t need it.
rm app/views/plivo/voice.html.erb
Edit the app/controllers/plivo_controller.rb file 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
21
22
23
24
25
26
27
28
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
19
20
21
22
23
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
To add a route for the outbound function in the PlivoController class, open the config/routes.rb file and change the line:
get 'plivo/voice'
to
get 'plivo/outbound'
Now plivo_controller is ready. Use this command to initiate an outbound call.
rails server
Your local development server will be started and you can test the application for outbound calls via the URL http://localhost:3000/plivo/outbound/.