Technical Guide: Migrating from Twilio to Plivo

    Introduction

    Migrating from Twilio to Plivo is a seamless and painless process. The two companies’ API structures, implementation mechanisms, XML structure, SMS message processing, and voice call processing are similar. We wrote this technical comparison between Twilio and Plivo APIs so that you can scope the code changes for a seamless migration.

    Understanding the differences between Twilio and Plivo development

    Most of the APIs and features that are available on Twilio are also available on Plivo and the implementation mechanism is easier as the steps involved are almost identical. This table gives a side-side comparison of the two companies’ features and APIs. An added advantage with Plivo is that not only can you code using the old familiar API/XML method, you can also implement your use cases using PHLO (Plivo High Level Objects), a visual workflow builder that lets you create workflows by dragging and dropping components onto a canvas — no coding required.

    Features and APIsTwilioPlivoSimilaritiesImplementation Interface
    Voice API: Make phone callsRequest and response variables’ structureAPI
    PHLO
    Programmatically manage call flowsTwimlPlivo XMLXML element and its attributes structureXML
    PHLO
    Geo PermissionsFeature parityConsole
    Number Lookup APIAPI ParityAPI
    Phone number managementFeature parityAPI
    Console
    Call InsightsFeature parityConsole
    Validating RequestsFeature parityAPI
    XML
    SubaccountsFeature parityAPI
    Speech recognitionFeature parityXML
    SSML (Speech Synthesis Markup Language)Feature parityXML
    PHLO
    Browser and Mobile SDKsFeature parityBrowser
    Android
    iOS
    TranscriptionFeature parityAPI
    XML
    PHLO
    Custom SIP HeadersFeature parityAPI
    XML
    PHLO
    Browser SDK
    Mobile SDKs
    HTTP callbacksFeature parityAPI
    XML
    PHLO

    Plivo account creation

    Start by signing up for a free trial account that you can use to experiment with and learn about our services. The free trial account comes with free credits, and you can add more as you go along. You can also add a phone number to your account to start testing the full range of our voice and SMS features. A page in our support portal walks you through the signup process.

    You can also port your numbers from Twilio to Plivo, as we explain in this guide.

    Migrating your Voice application

    As mentioned earlier, you can migrate your existing application from Twilio to Plivo by refactoring the code, or you can try our intuitive visual workflow builder PHLO. If you prefer the API approach, you can follow one of the voice quickstart guides based on your preferred language and web framework. Plivo offers server SDKs in seven languages: PHP, Node.js, .NET, Java, Python, Ruby, and Go. For another alternative that lets you evaluate Plivo’s SMS APIs and their request and response structure, use our Postman collections.

    How to make an outbound call

    Let’s take a look at the process of refactoring the code to migrate your app from Twilio to Plivo to set up a simple Python application to make an outbound call by changing just a few lines of code.

    TwilioPlivo
    import os
    from twilio.rest import Client
    
    account_sid = os.environ["TWILIO_ACCOUNT_SID"]
    auth_token = os.environ["TWILIO_AUTH_TOKEN"]
    client = Client(account_sid, auth_token)
    
    call = client.calls.create(
    url='http://demo.twilio.com/docs/voice.xml',
                           to='+14155551212',
                           from_='+15017122661'
                       )
    
    print(call)
       
    import os, plivo
    
    
    auth_id = os.environ["PLIVO_AUTH_ID"]
    auth_token = os.environ["PLIVO_AUTH_TOKEN"]
    client = plivo.RestClient(auth_id, auth_token)
    
    call = client.calls.create(
        from_='+14151234567',
        to_='+14157654321',
    answer_url='http://s3.amazonaws.com/static.plivo.com/answer.xml',
        answer_method='GET', )
    print(call)

    Alternatively, you can implement the same functionality using one of our PHLO templates. For example, if you want to make an outbound call, your PHLO would be this:

    Create a PHLO for outbound calls

    How to receive an incoming call

    You can migrate an application for receiving and handling an incoming call from Twilio to Plivo just as seamlessly, as in this example:

    TwilioPlivo
    from flask import Flask
    from twilio.twiml.voice_response import VoiceResponse
    
    app = Flask(__name__)
    
    
    @app.route("/receive_call", methods=['GET', 'POST'])
    def receive_call():
        """Respond to incoming phone calls with a 'Hello world' message"""
        # Start our TwiML response
        resp = VoiceResponse()
    
        # Read a message aloud to the caller
        resp.say("hello world!", voice='alice')
    
        return str(resp)
    
    if __name__ == "__main__":
        app.run(debug=True)
       
    from flask import Flask, request, make_response
    from plivo import plivoxml
    
    app = Flask(__name__)
    
    
    
    @app.route('/receive_call', methods=['GET','POST'])
    def receive_call():
        # Generate a Speak XML with the details of the text to play on the call.
        response = (plivoxml.ResponseElement()
                .add(plivoxml.SpeakElement('Hello, you just received your first call')))
        return(response.to_string())
    
    if __name__ == "__main__":
        app.run(host='0.0.0.0', debug=True)

    Here again, you can implement the same functionality using one of our PHLO templates. Your PHLO would look like:

    Create a PHLO to receive incoming call

    For more information about migrating your Voice applications to Plivo, check out our detailed use case guides, available for all seven programming languages and PHLO.

    How to forward an incoming call

    You can migrate an application for forwarding an incoming call from Twilio to Plivo just as seamlessly, as in this example:

    TwilioPlivo
    from flask import Flask
    from twilio.twiml.voice_response import Dial, VoiceResponse, Say
    
    app = Flask(__name__)
    
    
    @app.route("/forward_call", methods=['GET', 'POST'])
    def forwardcall():
       """Forward the incoming phone calls to connect the caller to another party"""
       # Start our TwiML response
       response = VoiceResponse()
    
       # Dial verb to forward the call
       response.dial('415-123-4567')
       response.say('Goodbye')
    
       return str(response)
    
    if __name__ == "__main__":
       app.run(debug=True)
       
    from flask import Flask, request, make_response, Response
    from plivo import plivoxml
    
    app = Flask(__name__)
    
    
    
    @app.route('/forward_call', methods=['GET', 'POST'])
    def forwardcall():
    
        response = plivoxml.ResponseElement()
        response.add(
            plivoxml.DialElement().add(
             plivoxml.NumberElement('15671234567')))
        return(response.to_string())
    
    if __name__ == '__main__':
        app.run(host='0.0.0.0', debug=True)

    Here again, you can implement the same functionality using one of our PHLO templates. Your PHLO would look like:

    Create a PHLO to receive incoming call

    For more information about migrating your Voice applications to Plivo, check out our detailed use case guides, available for all seven programming languages and PHLO.

    More use-cases

    You can migrate your applications serving various other use-cases like the following ones too:

    Porting your existing numbers from Twilio to Plivo

    If you wish to continue using your phone numbers from Twilio, you can port the numbers to Plivo painlessly without having any downtime on your services for your customers. Phone number porting must be requested by a phone number’s owner. Here’s an overview of the process for porting a phone number to Plivo:

    1. Submission of a porting request with documentation
    2. Verification of the porting request
    3. Porting request submission to the gaining carrier
    4. Porting request submission to the losing carrier
    5. Response from the losing carrier
    6. Firm Order Commitment or porting date set

    You can check our number porting guide to initiate the process.

    Buy new phone numbers for your migrated app

    You can buy new phone numbers on the Plivo platform for your migrated applications as well. Plivo provides a self-serve console to buy new numbers and to manage them. You can also use the Phone numbers API for number management. You can check this guide to learn more.