Upgrade from Node.js Legacy to v4.8.0 or Latest Version

Introduction

This is a major application update. Plivo recommends you always use the latest or an active version of our SDKs for guaranteed security, stability, and uptime. The active SDK versions are designed to handle intermittent and regional failures of API requests. In addition, they offer a host of security features, such as protection against DoS attacks and bot detection for suspicious user agents.

Deprecation notice: We’re deprecating Plivo Node SDK legacy versions lower than v4.8.0 on January 31, 2022. If you use a deprecated version of our SDK after that date, your API requests and voice calls may fail intermittently. Plivo will no longer provide bug fixes to these versions, and our support team may ask you to upgrade before debugging issues.

Migrate your applications

Node.js version support

The 4.x version of the Plivo SDK is compatible with Node.js versions 5.5 and higher.

Use the command npm install plivo@4.8.0 to upgrade to the active version of the SDK, or npm install plivo@latest to upgrade to the latest version.

After you upgrade to the latest version of the SDK, you should check every program that depends on it and make changes to the syntax for several kinds of operations. Here are examples of how coding differs between the deprecated legacy version of the SDK and the latest active versions.

Import the SDK

Legacy Latest
var plivo = require('plivo');
   
var plivo = require('plivo');
   

Initialize

Legacy Latest
var p = plivo.RestAPI({
  authId: '<auth_id>',
  authToken: '<auth_token>'
});
   
var client = new plivo.Client("<auth_id>","<auth_token>");
   

Access resources

Legacy Latest
p.make_call(params, function (status, response) {
    console.log('Status: ', status);
    console.log('API Response:\n', response);
});
   
client.calls.create(params).then(function (response) {
        console.log(response);
    }, function (err) {
        console.error(err);
    });
   

Make a call

Legacy Latest
var plivo = require('plivo');
var p = plivo.RestAPI({
  authId: '<auth_id>',
  authToken: '<auth_token>'
});

var params = {
    'to': '2025552323',    
    'from' : '2025551212', 
    'answer_url' : "https://s3.amazonaws.com/static.plivo.com/answer.xml",
    'answer_method' : "GET"
};
p.make_call(params, function (status, response) {
    console.log('Status: ', status);
    console.log('API Response:\n', response);
});
   
var plivo = require('plivo');
(function main() {
    'use strict';
    var client = new plivo.Client("<auth_id>","<auth_token>");
    client.calls.create(
        "+12025551212", // from
        "+12025552323", // to
        "https://s3.amazonaws.com/static.plivo.com/answer.xml", 
        {
            answerMethod: "GET",
        },
    ).then(function (response) {
        console.log(response);
    }, function (err) {
        console.error(err);
    });
})();
   

Dial XML

Legacy Latest
var plivo = require('plivo');

var response = plivo.Response();

var params = {
    'dialMusic': "https://<yourdomain>.com/dial_music/"
};
var dial = response.addDial(params);

var first_number = "12025551212";
dial.addNumber(first_number);

console.log(response.toXML());
   
var plivo = require('plivo');

var response = plivo.Response();

var params = {
    'dialMusic': "https://<yourdomain>.com/dial_music/"
};
var dial = response.addDial(params);

var first_number = "12025551212";
dial.addNumber(first_number);

console.log(response.toXML());
   

Conference XML

Legacy Latest
var plivo = require('plivo');
var response = plivo.Response();
var params = {
    'startConferenceOnEnter': "false",
    'waitSound': "https://<yourdomain>.com/waitMusic/"
};
var conference_name = "My Room";
response.addConference(conference_name, params);
console.log(response.toXML());
   
var plivo = require('plivo');


var response = plivo.Response();

var params = {
    'startConferenceOnEnter': "false",
    'waitSound': "https://<yourdomain>.com/waitMusic/"
};
var conference_name = "My Room";
response.addConference(conference_name, params);

console.log(response.toXML());
   

Record API

Legacy Latest
var plivo = require('plivo');
var p = plivo.RestAPI({
        "authId": "<auth_id>",
        "authToken": "<auth_token>"
    });
 var params = {'call_uuid':call_uuid};   
var response = p.record(params);
console.log(response);
   
var plivo = require('plivo');
(function main() {
    'use strict';
    var client = new plivo.Client("<auth_id>","<auth_token>");
    client.calls.record(
        "eba53b9e-8fbd-45c1-9444-696d2172fbc8", // call uuid
    ).then(function (response) {
        console.log(response);
    }, function (err) {
        console.error(err);
    });
})();
   

Record XML

Legacy Latest
var plivo = require('plivo');

var response = plivo.Response();

var params = {
    'action': "https://<yourdomain>.com/get_recording/",
    'startOnDialAnswer': "true",
    'redirect': "false"
};
response.addRecord(params);

var dial = response.addDial();
var number = "12025552323";
dial.addNumber(number);

console.log(response.toXML());
   
var plivo = require('plivo');

var response = plivo.Response();

var params = {
    'action': "https://<yourdomain>.com/get_recording/",
    'startOnDialAnswer': "true",
    'redirect': "false"
};
response.addRecord(params);

var dial = response.addDial();
var number = "12025552323";
dial.addNumber(number);

console.log(response.toXML());