SMS - Tutorial: Send an SMS in Node.js using the Telesign SDK

This tutorial teaches you how to use the Telesign Node.js SDK to send an SMS. The complete sample code for this tutorial is available on GitHub here.

Before you begin

  • Authentication credentials: Your Customer ID and API Key. If you need help finding these items, go to the support article How do I find my Customer ID and API Key.
  • Testing device: A mobile phone on which you can receive SMS.
  • Telesign Self-service Node.js SDK: Install the Self-service Node.js SDK. Source code and installation instructions are on GitHub.

Set up your project

  1. Create a new directory for your project and then enter it. If you plan to create multiple Node.js projects that use Telesign, we recommend that you group them within a telesign_integrations directory.
cd telesign_integrations
mkdir sms
cd sms
  1. Create a new file called send_sms.js and open it in your editor.
touch send_sms.js

Create code to send an SMS

  1. Import the Telesign SDK as a dependency.
var TeleSignSDK = require('telesignsdk');
  1. Define variables to store your authentication credentials. For testing purposes, you can just overwrite the default values below rather than use environment variables.
const customerId = process.env.CUSTOMER_ID || "FFFFFFFF-EEEE-DDDD-1234-AB1234567890";
const apiKey = process.env.API_KEY || "ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";
  1. Define a variable to hold the recipient's phone number. For this tutorial, hardcode your testing device's phone number.
const phoneNumber = process.env.PHONE_NUMBER || "1234567890";
  1. Define variables for the message text and the Telesign abbreviation describing the message type. For purposes of this tutorial, use the "ARN" abbreviation (alerts, reminders, and notifications).
const message = "Hello world";
const messageType = "ARN";
  1. Instantiate a Telesign messaging client object with your authentication credentials.
const client = new TeleSignSDK( customerId, apiKey);
  1. Define a function to display the response body in the console for debugging purposes. In your production code, you would likely remove this.
function printResponse(error, responseBody) {
    if (error === null) {
        console.log("\n## Response: ##\n" + JSON.stringify(responseBody));
    } else {
        console.error("Unable to send message. " + error);
  1. Make the request and capture the response. Include your function to display the response as a callback.
client.sms.message(printResponse, phoneNumber, message, messageType);

Sample code

The complete sample code for this tutorial can be found on GitHub.