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.
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);
});