SMS - Tutorial: Send an SMS message

This page explains how to use Telesign SDKs to send an SMS message. You can use this to send alerts, reminders, and notifications for a variety of situations such as:

  • Weather updates
  • Status of a package being delivered
  • Reminder for appointments or events
  • A notification about a special offer or promotion
  • Notifications about a change in status to an account, for example to let someone know their password changed

Full sample code is available at the end of this tutorial.

Before you begin

Make sure you have the following before you start:

  • 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.

Install the SDK

  1. Log in to GitHub and choose the SDK in your preferred language.
  2. Download or clone the repository. If you download it, extract the repository from the .ZIP file.
  3. Use these commands to install the SDK:
npm install telesignsdk -save
compile files('path/to/jar/telesignenterprise-(insert latest version).jar')
<dependency>
    <groupId>com.telesign</groupId>
    <artifactId>telesign</artifactId>
    <version>[current_version]</version>
</dependency>
# From a terminal run:
pip install telesign

shell Ruby

From a terminal run:

gem install telesign

# From a terminal run:
composer require telesign/telesign
```shell C#
$ nuget pack .\Path\To\csharp_telesign_enterprise\TelesignEnterprise\TelesignEnterprise.csproj
$ Install-Package .\Path\To\TelesignEnterprise-(insert latest version).nupkg

Send an SMS message

  1. Include the Telesign SDK and any necessary language-specific dependencies.
var TeleSignSDK = require('telesignsdk');
package com.telesign.example.messaging;

import com.telesign.MessagingClient;
import com.telesign.RestClient;
from __future__ import print_function
from telesign.messaging import MessagingClient

#If you are working with a version of Python 3, you do not need the first import #statement (`from __future__ import print_function`).
require 'telesign'
<?php
require __DIR__ . "/../../vendor/autoload.php";
use telesign\sdk\messaging\MessagingClient;
using System;
  1. Define each of these variables:
    • customer_id (customerId for Java/C#) - Your Telesign-assigned Customer ID.
    • api_key (apiKey for Java/C#) - Your Telesign-assigned API key.
    • phone_number (phoneNumber for Java/C#) - The phone number to which you want to send the SMS. If you are doing a free trial, the phone number must be verified (verifying the number is not required if you are a paying customer). Include the complete phone number (with country code) including no spaces or special characters.
    • message - Include the message text here.
    • message_type (messageType for Java/C#) - The type of message you are sending. For this tutorial we'll choose "ARN" (for alerts, reminders, and notifications).
    • restEndpoint - (For Java only) The base endpoint.
const customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"; // Todo: find in teleportal.telesign.com
const apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="; // Todo: find in portal.telesign.com
const rest_endpoint = "https://rest-ww.telesign.com"; 
const timeout = 10*1000; // 10 secs

const client = new TeleSignSDK( customerId,
    apiKey,
    rest_endpoint,
    timeout // optional
    // userAgent
);

const phoneNumber = "Your test phone number with no special characters or spaces.";
const message = "You're scheduled for a dentist appointment at 2:30PM.";
const messageType = "ARN";
public class SendMessage {

    public static void main(String[] args) {

        String customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890";
        String apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";

        String phoneNumber = "Your test phone number with no special characters or spaces.";
        String message = "You're scheduled for a dentist appointment at 2:30PM.";
        String messageType = "ARN";
        String restEndpoint = "https://rest-ww.telesign.com";
customer_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
api_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="

phone_number = "The phone number you want to send an SMS to goes here."
message = "You're scheduled for a dentist appointment at 2:30PM."
message_type = "ARN"
customer_id = 'Your TeleSign Customer ID goes here.'
secret_key = 'Your TeleSign API key goes here.'

phone_number = 'The phone number you want to send an SMS to goes here.'
message = 'You\'re scheduled for a dentist appointment at 2:30PM.'
message_type = 'ARN'
$customer_id = "Your TeleSign Customer ID goes here.";
$secret_key = "Your TeleSign API key goes here.";
$phone_number = "The phone number you want to send an SMS to goes here.";
$message = "You're scheduled for a dentist appointment at 2:30PM.";
$message_type = "ARN";
namespace Telesign.Example.Messaging
{
    class SendMessage
    {
        static void Main(string[] args)
        {
            string customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890";
            string apiKey = "EXAMPLETE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";

            string phoneNumber = "Your test phone number with no special characters or spaces.";

            string message = "You're scheduled for a dentist appointment at 2:30PM.";
            string messageType = "ARN";
  1. Instantiate a MessagingClient object containing your Customer ID and API key. Send an SMS to the phone number containing the message and message type you provided. Store the response in response. For Node.js, you open a console log and create a messageCallback function to handle the results coming back from the messaging client. Then, you create the messaging client and call the messageCallback function.
console.log("## MessagingClient.message ##");

function messageCallback(error, responseBody) {
    if (error === null) {
        console.log(`Messaging response for messaging phone number: ${phoneNumber}` +
            ` => code: ${responseBody['status']['code']}` +
            `, description: ${responseBody['status']['description']}`);
    } else {
        console.error("Unable to send message. " + error);
    }
}

client.sms.message(messageCallback, phoneNumber, message, messageType);
        try {
            MessagingClient messagingClient = new MessagingClient(customerId, apiKey, restEndpoint);
            RestClient.TelesignResponse telesignResponse = messagingClient.message(phoneNumber, message, messageType, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
messaging = MessagingClient(customer_id, api_key, rest_endpoint="https://rest-ww.telesign.com")
response = messaging.message(phone_number, message, message_type)
messaging_client = Telesign::MessagingClient.new(customer_id, api_key, rest_endpoint: 'https://rest-ww.telesign.com')
response = messaging_client.message(phone_number, message, message_type)
$messaging = new MessagingClient($customer_id, $api_key, $rest_endpoint = "https://rest-ww.telesign.com");
$response = $messaging->message($phone_number, $message, $message_type);
            try
            {
                MessagingClient messagingClient = new MessagingClient(customerId, apiKey, restEndpoint: "https://rest-ww.telesign.com");
                RestClient.TelesignResponse telesignResponse = messagingClient.Message(phoneNumber, message, messageType);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to quit.");
            Console.ReadKey();
        }
    }
}
  1. You should receive an SMS message containing the message you specified at the phone number you specified.

Sample code

var TeleSignSDK = require('telesignsdk');

const customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"; // Todo: find in portal.telesign.com
const apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="; // Todo: find in portal.telesign.com
const rest_endpoint = "https://rest-ww.telesign.com"; 
const timeout = 10*1000; // 10 secs

const client = new TeleSignSDK( customerId,
    apiKey,
    rest_endpoint,
    timeout // optional
    // userAgent
);

const phoneNumber = "Your test phone number with no special characters or spaces.";
const message = "You're scheduled for a dentist appointment at 2:30PM.";
const messageType = "ARN";

console.log("## MessagingClient.message ##");

function messageCallback(error, responseBody) {
    if (error === null) {
        console.log(`Messaging response for messaging phone number: ${phoneNumber}` +
            ` => code: ${responseBody['status']['code']}` +
            `, description: ${responseBody['status']['description']}`);
    } else {
        console.error("Unable to send message. " + error);
    }
}

client.sms.message(messageCallback, phoneNumber, message, messageType);
package com.telesign.example.messaging;

import com.telesign.MessagingClient;
import com.telesign.RestClient;

public class SendMessage {

    public static void main(String[] args) {

        String customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890";
        String apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";

        String phoneNumber = "Your test phone number with no special characters or spaces.";
        String message = "You're scheduled for a dentist appointment at 2:30PM.";
        String messageType = "ARN";
        String restEndpoint = "https://rest-ww.telesign.com";
          
        try {
            MessagingClient messagingClient = new MessagingClient(customerId, apiKey, restEndpoint);
            RestClient.TelesignResponse telesignResponse = messagingClient.message(phoneNumber, message, messageType, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
from __future__ import print_function
from telesign.messaging import MessagingClient

customer_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
api_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="

phone_number = "Your test phone number with no special characters or spaces."
message = "You're scheduled for a dentist appointment at 2:30PM."
message_type = "ARN"

messaging = MessagingClient(customer_id, api_key, rest_endpoint="https://rest-ww.telesign.com")
response = messaging.message(phone_number, message, message_type)
require 'telesign'

customer_id = 'FFFFFFFF-EEEE-DDDD-1234-AB1234567890'
api_key = 'EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=='

phone_number = 'Your test phone number with no special characters or spaces.'
message = 'You\'re scheduled for a dentist appointment at 2:30PM.'
message_type = 'ARN'

messaging_client = Telesign::MessagingClient.new(customer_id, api_key, rest_endpoint: 'https://rest-ww.telesign.com')
response = messaging_client.message(phone_number, message, message_type)
<?php
require __DIR__ . "/../../vendor/autoload.php";
use telesign\sdk\messaging\MessagingClient;
$customer_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890";
$api_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";
$phone_number = "Your test phone number with no special characters or spaces.";
$message = "You're scheduled for a dentist appointment at 2:30PM.";
$message_type = "ARN";
$messaging = new MessagingClient($customer_id, $api_key, $rest_endpoint = "https://rest-ww.telesign.com");
$response = $messaging->message($phone_number, $message, $message_type);
using System;

namespace Telesign.Example.Messaging
{
    class SendMessage
    {
        static void Main(string[] args)
        {
            string customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890";
            string apiKey = "EXAMPLETE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";

            string phoneNumber = "Your test phone number with no special characters or spaces.";

            string message = "You're scheduled for a dentist appointment at 2:30PM.";
            string messageType = "ARN";

            try
            {
                MessagingClient messagingClient = new MessagingClient(customerId, apiKey, restEndpoint: "https://rest-ww.telesign.com");
                RestClient.TelesignResponse telesignResponse = messagingClient.Message(phoneNumber, message, messageType);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to quit.");
            Console.ReadKey();
        }
    }
}
curl -X POST https://rest-ww.telesign.com/v1/messaging \
-d phone_number=XXXXXXXX \
-d message="You have a dentist appointment at 2:15pm" \
-d message_type="ARN" \
-u "CUSTOMER_ID":"API_KEY"

Did this page help you?