How to Migrate Your Go Voice Application from Twilio to Plivo

How to Migrate Your Go Voice Application from Twilio to Plivo

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 APIs Twilio Plivo Similarities Implementation Interface
Voice API: Make phone calls Request and response variables’ structure API
PHLO
Programmatically manage call flows Twiml Plivo XML XML element and its attributes structure XML
PHLO
Geo Permissions Feature parity Console
Number Lookup API API Parity API
Phone number management Feature parity API
Console
Call Insights Feature parity Console
Validating Requests Feature parity API
XML
Subaccounts Feature parity API
Speech recognition Feature parity XML
SSML (Speech Synthesis Markup Language) Feature parity XML
PHLO
Browser and Mobile SDKs Feature parity Browser
Android
iOS
Transcription Feature parity API
XML
PHLO
Custom SIP Headers Feature parity API
XML
PHLO
Browser SDK
Mobile SDKs
HTTP callbacks Feature parity API
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: Python, 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 Go application to make an outbound call by changing just a few lines of code.

Twilio Plivo
package main

import (
    "fmt"
    "github.com/twilio/twilio-go"
    openapi "github.com/twilio/twilio-
    go/rest/api/v2010"
    "os"
)

func main() {
    from: =
    os.Getenv("TWILIO_FROM_PHONE_NUMBER")
    to: =
    os.Getenv("TWILIO_TO_PHONE_NUMBER")

        client: = twilio.NewRestClient()
    
        params: = & openapi.CreateCallParams {}
    params.SetTo(to)
    params.SetFrom(from)
    params.SetUrl("http://twimlets.com/holdmusic?
    Bucket=com.twilio.music.ambient")
    
    resp,
    err: = client.ApiV2010.CreateCall(params)
    if err != nil {
        fmt.Println(err.Error())
    } else {
        fmt.Println("Call Status: " + * resp.Status)
        fmt.Println("Call Sid: " + * resp.Sid)
        fmt.Println("Call Direction: " +
        * resp.Direction)
    }
}
   
package main

import (
    "fmt"
    "github.com/plivo/plivo-go/v7"
)

func main() {
    client, err: = plivo.NewClient("<auth_id>",
    "<auth_token>", & plivo.ClientOptions {})
    if err != nil {
        fmt.Print("Error", err.Error())
        return
    }
    response, err: = client.Calls.Create(
        plivo.CallCreateParams {
            From: "+14151234567",
            To: "+15671234567",
            AnswerURL:
"https://s3.amazonaws.com/static.plivo.com/answer.xml",
            AnswerMethod: "GET",
        },
    )
    if err != nil {
        fmt.Print("Error", err.Error())
        return
    }
    fmt.Printf("Response: %#v\n", response)
}

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:

Twilio Plivo
package main

import (
  "net/http"
  "encoding/xml"
)

type TwiML struct {
  XMLName xml.Name `xml:"Response"`

  Say    string `xml:",omitempty"`
}

func main() {
  http.HandleFunc("/twiml", twiml)
  http.ListenAndServe(":3000", nil)
}

func twiml(w http.ResponseWriter, r *
http.Request) {
  twiml := TwiML{Say: "Hello World!"}
  x, err := xml.Marshal(twiml)
  if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
  }

  w.Header().Set("Content-Type", "application/xml")
  w.Write(x)
}
   
package main

import (
	"fmt"
	"net/http"
	"github.com/plivo/plivo-go/v7"
)

func handler(w http.ResponseWriter, r *
http.Request) {

	response := xml.ResponseElement{
		Contents: []interface{} {
			new(xml.SpeakElement).
			AddSpeak("Hello, you just
      received your first call"),
		},
	}
	fmt.Printf(response.String())
}

func main() {
	http.HandleFunc("/receive_call/", handler)
	http.ListenAndServe(":8080", nil)
}

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:

Twilio Plivo
package main

import (
    "net/http"
    "encoding/xml"
)

type TwiML struct {
    XMLName xml.Name `xml:"Response"`

    Dial string `xml:",omitempty"`
}

func main() {
    http.HandleFunc("/twiml", twiml)
    http.ListenAndServe(":3000", nil)
}

func twiml(w http.ResponseWriter, r * 
http.Request) {
    twiml: = TwiML {
        Dial: "415-123-4567"
    }
    x,
    err: = xml.Marshal(twiml)
    if err != nil {
        http.Error(w, err.Error(), 
        http.StatusInternalServerError)
        return
    }

    w.Header().Set("Content-Type",
    "application/xml")
    w.Write(x)
}
   
package main

import (
    "net/http"
    "plivo-go/xml"
)

func handler(w http.ResponseWriter, r *
http.Request) {
    response: = xml.ResponseElement {
        Contents: [] interface {} {
            new(xml.DialElement).
            SetContents(
                [] interface {} {
                    new(xml.NumberElement).
                    SetContents
                    ("<destination_number>"),
                },
            ),
        },
    }
    w.Write([] byte(response.String()))
}

func main() {
    http.HandleFunc("/forward_call/", handler)
    http.ListenAndServe(":8080", nil)
}

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 other use cases too.

Simple and reliable

And that’s all there is to migrate your Go voice application from Twilio to Plivo. Our simple APIs work in tandem with our Premium Communications Network. See for yourself — sign up for a free trial account.

Get Volume Pricing

Thousands of businesses in more than 220 countries trust Plivo’s cloud communications platform

The best communications platform forthe world’s leading entertainment service

Frequently asked questions

No items found.
footer bg

Subscribe to Our Newsletter

Get monthly product and feature updates, the latest industry news, and more!

Thank you icon
Thank you!
Thank you for subscribing
Oops! Something went wrong while submitting the form.