How to Easily Migrate Your Node.js SMS Application from Twilio to Plivo

Migrating your Node.js 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.

Features and APIsTwilioPlivoSimilaritiesImplementation Interface
SMS API: Send SMS/MMS messagesRequest and response variables’ structureAPI
PHLO
Managed number pool for US/CA MessagingCopilotPowerpackFeature parityAPI
Console
Geo PermissionsFeature parityConsole
SMS Sender ID registrationFeature parityConsole
Number Lookup APIAPI ParityAPI
Phone number managementFeature parityAPI
Console
Validating RequestsFeature parityAPI
XML
SubaccountsFeature parityAPI
HTTP callbacksFeature parityAPI
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 Node.js 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: 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 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 Node.js application to send an SMS message by changing just a few lines of code.

TwilioPlivo
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);

client.messages
  .create({
     from: '<source_number>',
     to: '<destination_number>',
     body: 'Hello'
   })
  .then(message => console.log(message.sid));
   
const plivo = require('plivo');

const client = new plivo.Client("<auth_id>", "<auth_token>");
response = client.messages.create(
      { 
          src: "<source_number>", 
          dst: "<destination_number>",
          text: "Hello"
      }
      ).then(function (response) {
        console.log(response);
});

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:

TwilioPlivo
const http = require('http');
const express = require('express');
const MessagingResponse = require('twilio').twiml.MessagingResponse;

const app = express();

app.post('/sms', (req, res) => {
  const twiml = new MessagingResponse();

  twiml.message('Hello');

  res.writeHead(200, {'Content-Type': 'text/xml'});
  res.end(twiml.toString());
});

http.createServer(app).listen(1337, () => {
  console.log('Express server listening on port 1337');
});
   
const plivo = require('plivo');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();

app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(function(req, response, next) {
    response.contentType('application/xml');
    next();
});
app.set('port', (process.env.PORT || 3000));
app.all('/reply_sms/', function(request, response) {
    let from_number = request.body.From || request.query.From;
    let to_number = request.body.To || request.query.To;
    let text = request.body.Text || request.query.Text;
    console.log('Message received - From: ' + from_number + ', To: ' + to_number + ', Text: ' + text);

    //send the details to generate an XML
    let r = plivo.Response();
    let params = {
        'src': to_number,
        'dst': from_number,
    };
    let message_body = "Hello";
    r.addMessage(message_body, params);
    console.log(r.toXML());
    response.end(r.toXML());
});
app.listen(app.get('port'), function() {
    console.log('Node app is running on port', app.get('port'));
});

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

TwilioPlivo
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);

client.messages
  .create({
     from: '<source_number>',
     to: '<destination_number>',
     body: 'Hello',
     mediaUrl: ['https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg']
   })
  .then(message => console.log(message.sid));
});
   
var plivo = require('plivo');
(function main() {
    'use strict';
    var client = new plivo.Client("<auth_id>", "<auth_token>");
    client.messages.create(
      { 
          src: "<source_number>", 
          dst: "<destination_number>",
          text: "Hello",
          type: "mms",
          media_urls: ["https://media.giphy.com/media/26gscSULUcfKU7dHq/source.gif"],
          media_ids: ["801c2056-33ab-499c-80ef-58b574a462a2"]
      }
      ).then(function (response) {
        console.log(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 SMS

More use-cases

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

Simple and reliable

And that’s all there is to migrate your Node.js SMS app from Twilio to Plivo either using Plivo’s Node.js SDK or PHLO. Our simple APIs work in tandem with our comprehensive global network. You can also use Plivo’s premium direct routes that 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.

comments powered by Disqus

By submitting this form, you agree we may contact you in the manner described in our Privacy Policy