Send a Custom SMS

var TeleSignSDK = require('telesignenterprisesdk');

console.log("## verify.sms ##");

const customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"; // Todo: find in teleportal.telesign.com
const apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="; // Todo: find in teleportal.telesign.com
const phoneNumber = "Your test phone number with no special characters or spaces goes here.";
const optionalParams = {template: "Your Widgets 'n' More verification code is $$CODE$$."};

const client = new TeleSignSDK(customerId, apiKey);

// Callback handler for SMS request
function smsCallback(error, responseBody) {
    if (error === null) {
        console.log(`SMS response for phone number: ${phoneNumber}` +
            ` => code: ${responseBody['status']['code']}` +
            `, description: ${responseBody['status']['description']}`);
    } else {
        console.error("Unable to send sms. " + error);
    }
}

// Send SMS request
client.verify.sms(smsCallback, phoneNumber, optionalParams);

The code sample above shows you how to send a custom SMS message containing a verification code using SMS Verify. In addition to this code sample, this tutorial provides a code sample that shows you how to send a custom SMS message in a different language using SMS Verify. You can access the walkthrough for the code sample above, and all information (including a code sample) about sending a custom SMS in a different language in the following sections:

This tutorial has the following sections:

Requirements

For this tutorial, the following is required:

  • customer ID - obtain from your account by logging in to teleportal.telesign.com (referred to as customer_id/customerId in this document)
  • API key - obtain from your account by logging in to teleportal.telesign.com (referred to as api_key/apiKey in this document)
  • Registration process - this tutorial assumes you already have implemented a way to collect the end user’s log in, password, and phone number, and that you already have a way to store this information after registration
  • SDK - Access to TeleSign’s GitHub repository for your selected language (you must request access from your Technical Account Manager):
  • Language Version
    • Node.js - 6+
    • Java - 7+
    • Python - 2.7+
    • Ruby - 2+
    • PHP - 5.6+
    • C# - 4.5+

Install the SDK

This section describes how to install TeleSign’s latest SDKs.

  1. Obtain your customer ID and API key.
  2. Log in to GitHub and navigate to the SDK in the language of your choice:
  3. Download or clone the repository. If you download it, extract the repository from the .ZIP file.
  4. To install the SDK for use, do the following:

Send a Custom SMS Message with a Verification Code

This section explains how to send a custom SMS message using SMS Verify. The sample code provided earlier is broken out into pieces and explained below.

  1. Begin by adding statements for including the appropriate part of the TeleSign SDK and any additional language specific functions you may need.
var TeleSignSDK = require('telesignenterprisesdk');
  1. Insert values for each of the items from customer_id/customerId through to phone_number/phoneNumber.
  • customer_id / customerId - Your TeleSign assigned customer ID, available in your account information in the portal.
  • api_key / apiKey - Your TeleSign assigned API key, available in your account information in the portal.
  • phone_number / phoneNumber - The phone number you want to use for the example. When you provide the number, it should be a string with no spaces or special characters. Include the complete number. For example, if you are doing a phone number for America, you would include the country code and the area code with the number. For example 16505551212.
const customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"; // Todo: find in teleportal.telesign.com
const apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="; // Todo: find in teleportal.telesign.com
const phoneNumber = "Your test phone number with no special characters or spaces goes here.";
  1. You can send custom SMS messages using the template parameter. To include a verification code in your message, incorporate $$CODE$$ as a placeholder. TeleSign will generate a verification code for you, and substitute it for `$$CODE$$.
const optionalParams = {template: "Your Widgets 'n' More verification code is $$CODE$$."};
  1. Instantiate a VerifyClient object containing your customer_id/customerId and api_key/apiKey. Send an SMS to the phone number containing the custom message and verification code. Store the response in response/telesignResponse. For node.js, you store the response in responseBody. And you send the SMS request after setting up the callback function to handle the response from the SMS request.
const client = new TeleSignSDK(customerId, apiKey);

// Callback handler for SMS request
function smsCallback(error, responseBody) {
    if (error === null) {
        console.log(`SMS response for phone number: ${phoneNumber}` +
            ` => code: ${responseBody['status']['code']}` +
            `, description: ${responseBody['status']['description']}`);
    } else {
        console.error("Unable to send sms. " + error);
    }
}

// Send SMS request
client.verify.sms(smsCallback, phoneNumber, optionalParams);
  1. You will send an SMS to the phone number you specify. You can examine the result of your phone call by looking at the contents of response/telesignResponse.

Send a Custom SMS Message in a Different Language

This section explains how to send a custom SMS message in a different language using SMS Verify. A sample is provided here if you want to cut n’ paste. Note that the only difference is that when you create your message to assign to the template variable, you write it in the language of your choice.

var TeleSignSDK = require('telesignenterprisesdk');


console.log("## verify.sms ##");

const customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"; 
// Todo: find in teleportal.telesign.com
const apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="; 
// Todo: find in teleportal.telesign.com
const phoneNumber = "Your test phone number with no special characters or spaces goes here.";
const optionalParams = {template: "Votre code de vérification Widgets 'n' More est $$CODE$$."};

const client = new TeleSignSDK(customerId, apiKey);

// Callback handler for SMS
function smsCallback(error, responseBody) {
    if (error === null) {
        console.log(`SMS response for phone number: ${phoneNumber}` +
            ` => code: ${responseBody['status']['code']}` +
            `, description: ${responseBody['status']['description']}`);
    } else {
        console.error("Unable to send sms. " + error);
    }
}

// Send SMS request
client.verify.sms(smsCallback, phoneNumber, optionalParams);

Code it Without the SDK

If you want to write all your own code, you will need to handle authentication yourself. You need the following documents: