1

I am using plivo for sending SMS to our users. I am implementing it with nodejs and as per the instructions of plivo's nodejs helper documentation I followed all the steps as given in the link below : plivo Nodejs helper official doc

Step 1. installed the library:

npm install plivo

Step 2: Initializing PlivoRestApi

var plivo = require('plivo');
var p = plivo.RestAPI({
  authId: 'Your AUTH_ID',
  authToken: 'Your AUTH_TOKEN'
});

Step 3: Triggering SMS

var params = {
    'src': '1111111111',
    'dst' : '2222222222',
    'text' : "Hello, how are you?"
};
p.send_message(params, function (status, response) {
    console.log('Status: ', status);
    console.log('API Response:\n', response);
});

and i am getting error as follow:

Debug: internal, implementation, error 
TypeError: Uncaught error: plivo.RestAPI is not a function

I am unable to find what is the exact issue with my code.

Eby Jacob
  • 1,418
  • 1
  • 10
  • 28
Jitendra
  • 3,135
  • 2
  • 26
  • 42

3 Answers3

3

Lowering npm package version to 0.4.0 will help.

STEP 1:

npm uninstall plivo --save

STEP 2:

npm install plivo@0.4.0 --save

Flow the steps and try to execute the program. It worked for me !

ted
  • 13,596
  • 9
  • 65
  • 107
2

According to the technical support team of Plivo i was using latest sdk with an older example and that is why my code was not working. By following the below link and i tried to implementing the latest example:

https://api-reference.plivo.com/latest/node/resources/message/send-a-message

Here is my new code snippet which works for me:

var plivo = require('plivo');
var client = new plivo.Client(Config.plivoCredentials.authId,Config.plivoCredentials.authToken);
    client.messages.create(
        "14153336666", // src
        "+918619249XXX", // dst
        "Test Message", // text
    ).then(function (response) {
        console.log(response);
    }, function (err) {
        console.error(err);
    });
Jitendra
  • 3,135
  • 2
  • 26
  • 42
1

You should use the Plivo client this way:

let plivo = require('plivo');
let client = new plivo.Client('Your AUTH_ID', 'Your AUTH_TOKEN');

client.messages.create(
          '1111111111',
          '2222222222',
          'Hello, how are you?'
        ).then(function(response) {
          console.log(response)
        });
Yan
  • 433
  • 2
  • 16