Send SMS messages via Plivo using Node.js

Nixon Samuel
3 min readMay 13, 2021

--

You can send your first SMS message using Plivo Node.js SDK within 5 minutes. This article guides you through how to use Plivo SMS API to send SMS from your application with Node.js. First, let’s make sure you meet the prerequisites before we dive into the code.

Prerequisites

  • Sign-up for a Plivo account if you haven’t already!
  • Plivo Auth ID and Auth Token: You will find your Plivo Auth ID and Auth Token on the home screen of your Plivo console.
  • Plivo Phone Number: You must have an SMS-enabled Plivo phone number to send messages to the US and Canada. Purchase numbers from the Numbers section of your Plivo console. You can also purchase numbers using the Numbers API.

Send an SMS message

In this section, we’ll send an SMS message with GSM characters, Unicode characters, and emojis, and a multipart message in the text body.

Send an SMS message with GSM characters

Now you’re ready to start. Create a file called sendSms.js and paste in this code:

const plivo = require('plivo');
const client = new plivo.Client('<auth_id>','<auth_token>');
client.messages.create(
'+14156667777',
'+14156667778',
'Hello, world!'
).then(function(message_created) {
console.log(message_created)
});

Send an SMS message with emojis

You can use this code to send an SMS with emojis in the message body:

const plivo = require('plivo');
const client = new plivo.Client('<auth_id>','<auth_token>');
client.messages.create(
'+14156667777',
'+14156667778',
'👋 Hello from Plivo!'
).then(function(message_created) {
console.log(message_created)
});

Send an SMS message with Unicode characters

You can use this code to send an SMS with Unicode characters in the message body:

const plivo = require('plivo');
const client = new plivo.Client('<auth_id>','<auth_token>');
client.messages.create(
'+14156667777',
'+14156667778',
'你好,世界!'
).then(function(message_created) {
console.log(message_created)
});

Send a multipart SMS message

You can use this code to send an SMS message with a multipart message body. The message will be sent to the destination number in parts and will be concatenated at the recipient’s end.

const plivo = require('plivo');
const client = new plivo.Client('<auth_id>','<auth_token>');
client.messages.create(
'+14156667777',
'+14156667778',
'This randomly generated text can be used in your layout (webdesign , websites, books, posters ... ) for free. This text is entirely free of law. Feel free to link to this site by using the image below or by making a simple text link'
).then(function(message_created) {
console.log(message_created)
});

Replace the placeholders auth_id and auth_token with actual values from your Plivo Console. Save the file and run it with the command:

node sendSms.js

An SMS message will be sent to the destination number specified in the code. To receive incoming SMS messages on your Plivo number, follow the Quickstart guide.

Note: You can check the Encoding and Concatenation guide to learn how Plivo manages GSM/Unicode characters in the message body.

Conclusion

And that’s all there is to sending SMS messages using Plivo’s Node.js SDK. Don’t use Node.js? Don’t worry — Plivo has SDKs for Java, Python, PHP, Ruby, .NET Core, .NET Framework, and Go.

Originally published at https://www.plivo.com on Mar 15, 2021.

--

--