paint-brush
Migrating a Voice-Enabled Application from Twilio to Plivoby@plivo
244 reads

Migrating a Voice-Enabled Application from Twilio to Plivo

by PlivoMarch 25th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Twilio and Plivo enjoy feature parity in virtually every aspect. The two companies’ API structures, implementation mechanisms, XML structure, SMS message processing, and voice call processing are similar. Plivo offers server SDKs in seven languages: PHP, Node.js,.NET, Java, Python, Ruby, and Go. You can migrate your existing application from Twilio to Plivo by refactoring the code. Plivio’s key principles is to keep things simple for developers while we allow them to build complex applications.

Company Mentioned

Mention Thumbnail
featured image - Migrating a Voice-Enabled Application 
from Twilio to Plivo
Plivo HackerNoon profile picture

Because Twilio has high name recognition, many organizations consider it first when investigating communications platforms as a service (CPaaS). After trying Twilio, though, they may find themselves less than completely satisfied, maybe because of high pricing or unsatisfactory support or some other factor. Fortunately, highly regarded Twilio alternatives can help ease the pain. We suggest Plivo, which earns the highest marks for customer satisfaction among cloud communications platforms on G2.


If you’re not satisfied with Twilio, you don’t have to rip it out and replace it with a Twilio alternative. You can put Plivo in place for a pilot program for a single use case and see how it performs. If you’re satisfied, you can switch over, or you can use Plivo in parallel with Twilio, or as a backup alternative in case your primary provider experiences downtime.


Migrating from Twilio to Plivo is simple. The two companies’ API structures, implementation mechanisms, XML structure, SMS message processing, and voice call processing are similar. Twilio and Plivo enjoy feature parity in virtually every aspect, including


  • Voice API
  • SMS/MMS API
  • Programmatically managing call flows
  • Geo permissions
  • Number lookup API
  • Phone number management
  • Validating requests
  • Subaccounts
  • Speech recognition
  • SSML (Speech Synthesis Markup Language)
  • Browser and mobile SDKs
  • Transcription
  • Custom SIP headers
  • HTTP callbacks


You can migrate your existing application from Twilio to Plivo by refactoring the code, or you can try Plivo High-Level Objects (PHLO), an intuitive visual workflow builder. Follow one of Plivo’s quickstart guides for your preferred language and web framework. Plivo offers server SDKs in seven languages: PHP, Node.js, .NET, Java, Python, Ruby, and Go.

How to Make an Outbound Call

Let’s take a look at the code for a Ruby application that makes an outbound call in both Twilio to Plivo. Whether you use Ruby or one of the other supported languages, you can migrate from one platform to the other by refactoring just a few lines of code.

Twilio

require 'rubygems'
require 'twilio-ruby'

account_sid = ENV['<TWILIO_ACCOUNT_SID>']
auth_token = ENV['<TWILIO_AUTH_TOKEN>']
@client = Twilio::REST::Client.new(account_sid, auth_token)

call = @client.calls.create(
            url: 'http://demo.twilio.com/docs/classic.mp3',
            to: '+1415555222',
            from: '+14155551111'
)
puts call.sid

Plivo

require 'rubygems'
require 'plivo'

include Plivo
include Plivo::Exceptions

auth_id = ENV['<PLIVO_AUTH_ID>']
auth_token = ENV['<PLIVO_AUTH_TOKEN>']

api = RestClient.new(auth_id,auth_token)

begin
  response = api.calls.create(
    '+14155551111',
    ['+14155552222'],
    'https://s3.amazonaws.com/static.plivo.com/answer.xml'
  )

  puts response
rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end

How to Receive an Incoming Call

You can migrate an application for receiving and handling an incoming call just as easily.

Twilio

require 'sinatra'
require 'twilio-ruby'

post '/twiml' do
  # Start our TwiML response
  Twilio::TwiML::VoiceResponse.new do |r|
    r.say(message: 'Hello, world!', voice: 'alice')
  end.to_s
end

Plivo

include Plivo
include Plivo::XML
include Plivo::Exceptions

class PlivoController < ApplicationController
 def inbound
    response = Response.new
    speak_body = 'Hello, world!'
    response.addSpeak(speak_body)

    xml = Plivo::PlivoXML.new(response)
    render xml: xml.to_xml
 end
end

How to Forward an Incoming Call

The same goes for an application that automatically forwards an incoming call.

Twilio

require 'sinatra'
require 'twilio-ruby'

post '/twiml' do

   response = Twilio::TwiML::VoiceResponse.new
   response.dial(number: '415-234-5678')
   response.say(message: 'Goodbye')
   puts response
   end.to_s
end

Plivo

def forward
   response = Response.new
   dial = response.addDial()
   dest_number = "415-234-5678"
   dial.addNumber(dest_number)

   xml = PlivoXML.new(response)
   puts xml.to_xml
   render xml: xml.to_xml
 end


We don’t want to overload you with code here (especially if you use a language other than Ruby). You can get more information about how to implement voice applications in Plivo from the use case guide documentation, available for all seven programming languages and PHLO.


One of Plivo’s key principles is to keep things simple for developers while we allow them to build complex applications. See for yourself how simple it is for a Twilio developer to pick up Plivo.

Simple and Reliable

Plivo’s simple APIs work in tandem with a comprehensive global network to let you build robust voice applications with low latency and high call quality. See for yourself by signing up for a free Plivo trial account that you can experiment with, which comes with free credits.