Skip to main content

How to Migrate Your Java SMS Application from Twilio to Plivo

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

December 10, 2021 · By Team Plivo
How to Migrate Your Java SMS Application from Twilio to Plivo

Migrating your Java SMS app 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 so that you can scope between Twilio and Plivo APIs 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.

.support-table td p{    font-size: 16px !important;; }

.support-table p{    margin: 0; }

.support-table tr:first-child td{    background: #f9fff8;    padding: 1rem; }

.support-table td{    padding-bottom: 1rem;    width: 25%;    padding: 1rem; }

.support-table td {    border-right: solid 1px #e5e5e5; } .support-table td:last-child{    border: 0; }

table.no-header-default-table {    width: 100%;    margin-bottom: 2rem; }

table.no-header-default-table td {    width: 25%;    border: 1px solid;    padding: 10px 1rem;    vertical-align: middle; }

table.no-header-default-table td p{ margin-bottom: 0 !important; }

._blog p + ul {    margin-top: -30px !important; }

h2.question{    margin: 0 0 21px;    font-family: Soleil;    font-size: 36px;    font-weight: normal;    font-stretch: normal;    font-style: normal;    line-height: 1.67;    letter-spacing: normal;    color: var(—deep-blue);  }

 div.answer{    margin-bottom: 1rem;    font-size: 16px;  }  a.green-cta{      color: #fff;      background-color: #03a94a;      border: 1px solid #03a94a;      border-radius: .25rem;      text-transform: uppercase;      font-size: 14px;      line-height: 1.2;      font-weight: 600;      white-space: pre-wrap;      box-shadow: 0 11px 40px -17px #036b17;      padding: 12px 28px;      text-align: center;      margin: 0 .8125rem .3125rem;  }  a.green-outer-cta{      color: #03a94a;      background-color: transparent;      background-image: none;      border: 1px solid #03a94a;      border-radius: .25rem;      text-transform: uppercase;      font-size: 14px;      line-height: 1.2;      font-weight: 600;      white-space: pre-wrap;      box-shadow: 0 11px 40px -17px #036b17;      padding: 12px 28px;      text-align: center;      margin: 0 .8125rem .3125rem;  }  a.blue-cta{      box-shadow: 0 11px 40px -17px #05006d;      color: #fff;      background-color: #05006d;      border: 1px solid #05006d;      border-radius: .25rem;      text-transform: uppercase;      font-size: 14px;      line-height: 1.2;      font-weight: 600;      white-space: pre-wrap;      padding: 12px 28px;      text-align: center;      margin: 0 .8125rem .3125rem;  }    a.blue-outer-cta{      box-shadow: 0 11px 40px -17px #05006d;      color: #05006d;      background-color: transparent;      background-image: none;      border: 1px solid #05006d;      border-radius: .25rem;      text-transform: uppercase;      font-size: 14px;      line-height: 1.2;      font-weight: 600;      white-space: pre-wrap;      padding: 12px 28px;      text-align: center;      margin: 0 .8125rem .3125rem;  }  .green-cta:hover, .green-outer-cta:hover, .blue-cta:hover, .blue-outer-cta:hover {    transform: none;    box-shadow: 0 0 0 rgba(50,50,93,.05),0 0 0 rgba(0,0,0,.03)!important;  }    .green-cta:hover, .blue-cta:hover{    color: #fff !important;;  }    .green-outer-cta:hover{    color: #03a94a !important;;  }

.blog-content .table-striped tbody tr:nth-of-type(odd) {  background-color: #F7F9FB;  } td, th {    padding: 1.5rem 0.65rem;    vertical-align: top;    text-align: left; } tr{ border: 1px solid #e5e5e5; } .no {    background: none;    height: auto;    width: auto;    display: inline;    vertical-align: unset; } .wrap-table span {    word-break: break-all; }  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Features and APIsTwilioPlivoSimilaritiesImplementation Interface
SMS API: Send SMS/MMS messagesRequest and response variables’ structure         API
           PHLO
   
Managed number pool for US/CA MessagingCopilotPowerpackFeature parity         API
           Console
   
Geo PermissionsFeature parityConsole
SMS Sender ID registrationFeature parityConsole
Number Lookup APIAPI ParityAPI
Phone number managementFeature parity         API
           Console
   
Validating RequestsFeature parity         API
           XML
   
SubaccountsFeature parityAPI
HTTP callbacksFeature parity            API
           XML
           PHLO
       

Plivo offers one unique advantage: Not only can you code using APIs and XML, 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.

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 Java SMS application

You can migrate your existing application from Twilio to Plivo by refactoring the code, or you can try our intuitive visual workflow builder PHLO. To continue working with the APIs, use one of the quickstart guides to set up a development environment for your preferred language. 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 send an SMS message

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 Java application to send an SMS message by changing just a few lines of code.

Twilio Plivo
   
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

public class Example {    public static final String ACCOUNT_SID = System.getenv(“TWILIO_ACCOUNT_SID”);    public static final String AUTH_TOKEN = System.getenv(“TWILIO_AUTH_TOKEN”);

   public static void main(String[] args) {        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);        Message message = Message.creator(                new com.twilio.type.PhoneNumber(“+14159352345”),                new com.twilio.type.PhoneNumber(“+14158141829”),                “Where’s Wallace?”)            .create();            System.out.println(message.getSid());    } }  

   

   
   
import java.io.IOException;
import java.net.URL;
import java.util.Collections;

import com.plivo.api.Plivo; import com.plivo.api.exceptions.PlivoRestException; import com.plivo.api.models.message.Message; import com.plivo.api.models.message.MessageCreateResponse;

class MessageCreate {      public static final String AUTH_ID = System.getenv(“PLIVO_AUTH_ID”);    public static final String AUTH_TOKEN = System.getenv(“PLIVO_AUTH_TOKEN”);    public static void main(String [] args)    {        Plivo.init(AUTH_ID,AUTH_TOKEN);        try        {            MessageCreateResponse response = Message.creator(“14151113333”,“+14151112222”,                    “Hello, this is test message”)                    .url(new URL(https://foo.com/sms_status/) )                    .create();            System.out.println(response);        }

       catch (PlivoRestException | IOException e)        {            e.printStackTrace();        }    } }

   

 .highlight pre{    background-color: rgb(33, 33, 48);    border-radius: 0;    padding: 15px 18px 15px 18px;  }  pre.lineno{    color: #fff;    opacity: .3;  }  .w-richtext figure {    max-width: 100%;    position: relative; }  

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

Create PHLO for outbound SMS

How to receive and reply to SMS

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

Twilio Plivo
   
import com.twilio.twiml.MessagingResponse;
import com.twilio.twiml.messaging.Body;
import com.twilio.twiml.messaging.Message;

import static spark.Spark.*;

public class SmsApp {    public static void main(String[] args) {                get(”/”, (req, res) -> “Hello Web”);                post(“/sms”, (req, res) -> {                    res.type(“application/xml”);                    Body body = new Body.Builder(“The Robots are coming! Head for the hills!“).build();                    Message sms = new Message.Builder().body(body).build();                    MessagingResponse twiml = new MessagingResponse.Builder().message(sms).build();                    return twiml.toXml();        });    } }  

   

   
   
package com.example.demo;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.xml.Message;
import org.springframework.boot.SpringApplication;
import 
org.springframework.boot.autoconfigure.SpringBootApplication;
import 
org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.plivo.api.exceptions.PlivoXmlException;
import com.plivo.api.xml.Response;

import java.io.IOException;

@SpringBootApplication @RestController public class PlivoSmsApplication {

   public static void main(String[] args) {        SpringApplication.run(PlivoSmsApplication.class, args);    }        // Receive incoming SMS    @PostMapping(“/incoming”)    public String postBody(String From, String To, String Text) {        System.out.println(From + ” ” + To + ” ” + Text);     return “Message received!”;    }        // Reply to incoming SMS    @GetMapping(value = “/reply”, produces = {“application/xml”})    public String getBody(String From, String To, String Text)    throws PlivoXmlException {        Response res = new Response().children(            new Message(To, From, “Thank you, we have received your request”));        return res.toXmlString();    }

}

   

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

With Dynamic Payload

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

How to send an MMS message

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 Java application to send an MMS message by changing just a few lines of code.

Twilio Plivo
   
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

import java.net.URI; import java.util.Arrays;

public class Example { public static final String ACCOUNT_SID = System.getenv(“TWILIO_ACCOUNT_SID”); public static final String AUTH_TOKEN = System.getenv(“TWILIO_AUTH_TOKEN”);

   public static void main(String[] args) {        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);        Message message = Message.creator(                new com.twilio.type.PhoneNumber(“+15558675310”),                new com.twilio.type.PhoneNumber(“+15017122661”),                “This is the ship that made the Kessel Run in fourteen parsecs?”) .setMediaUrl( Arrays.asList(URI .create(https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg)))            .create();

       System.out.println(message.getSid());    } }  

   

   
   
package com.plivo.api;
import java.io.IOException;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.media.Media;

public class SendSMS { public static final String AUTH_ID = System.getenv(“PLIVO_AUTH_ID”); public static final String AUTH_TOKEN = System.getenv(“PLIVO_AUTH_TOKEN”);    public static void main(String[] args) {    Plivo.init(AUTH_ID, AUTH_TOKEN);    MessageCreateResponse response = Message.creator(“+14151234567”,Collections.singletonList(“+14157654321”),        “Hello, from Java!“).type(MessageType.MMS)        .media_urls(new String[]{https://media.giphy.com/media/26gscSULUcfKU7dHq/source.gif})        .media_ids(new String[]{“801c2056-33ab-499c-80ef-58b574a462a2”})        .create();    System.out.println(response);      }   } }

   

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

Create PHLO for outbound MMS

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 Java SMS application from Twilio to Plivo. Our simple APIs work in tandem with our Premium Communications Network to guarantee the highest possible delivery rates and the shortest possible delivery times for your SMS messages. See for yourself — sign up for a free trial account.

T
Team Plivo
Plivo Blog