In order to send an SMS from our application in Nodejs, we can use TwilioAPI for doing so. We need to create an account on Twilio and specify details. Once we have done that we can use the following code to send an SMS.
// Twilio
Credentials
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = 'your_auth_token';
//require the
Twilio module and create a REST client
var client = require('twilio')(accountSid, authToken);
client.messages.create({
to: "+15XXXXXXXX",
from: "+15XXXXXXX0",
body: "Test Message from Twilio",
}, function(err, message) {
console.log(message.sid);
});
We need to specify to and from numbers. To is the number that is verified under Twilio account and from is the number that Twilio generates for you at the account setup.
Comments