Check Phone Type to Block VOIP

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-api.telesign.com"; // Todo: Enterprise customer, change this!
const timeout = 10*1000; // 10 secs

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

const phoneNumber = "Test phone number with no special characters or spaces goes here.";
const phoneTypeVOIP = "5";

console.log("## PhoneIDClient.phoneID ##");

function messageCallback(error, responseBody) {
    if (error === null) {
        console.log(`PhoneID response for phone number: ${phoneNumber}`
            + ` => code: ${responseBody['status']['code']}`
            + `, description: ${responseBody['status']['description']}`);

        if (responseBody['status']['code'] === 200) {
            if (responseBody['phone_type']['code'] === phoneTypeVOIP) {
                console.log("Phone type in request is VOIP");
            } else {
                console.log("Phone type in request is not VOIP");
            }
        }
    } else {
        console.error("Unable to get PhoneID. " + error);
    }
}

client.phoneid.phoneID(messageCallback, phoneNumber);

This quick start describes how to use TeleSign SDKs and PhoneID to check a phone number’s phone type and block Voice over Internet Protocol (VOIP). Typically you want to block VOIP numbers because they are often used for fraudulent activities such as account signup fraud. VOIP numbers are cheap, easy to buy in bulk and can easily be used by a fraudster to sign up for an account that requires a phone number as part of registration. After signup, they may abuse promotions and bonuses, spam other users, create fake likes, comments, or product reviews, sell fake/bulk accounts and other similar fraudulent activities. For this reason, blocking VOIP numbers can be a key part of securing your account registration process.

This quick start includes the following sections:

NOTE:

If you do not have a customer ID, sign up for TeleSign’s Free Trial.

Requirements

For this quick start, the following is required:

  • customer ID - obtain from your account by logging in to portal.telesign.com (referred to as customer_id/customerId in this document)
  • API key - obtain from your account by logging in to portal.telesign.com (referred to as api_key/apiKey in this document)
  • SDK - Access to TeleSign’s GitHub repository for your selected language:
  • Node.js
  • Java
  • Python
  • Ruby
  • PHP
  • C#
  • Language Version
  • Node.js - 6+
  • Java - 7+
  • Python - 2.7+
  • Ruby - 2+
  • PHP - 5.6+
  • C# - 4.5+
  • Verified Phone Number - To use TeleSign’s free trial, you must verify a phone number before using it.
NOTE:

If you do not have a customer ID, sign up for TeleSign’s Free Trial.

Install the SDK

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

Check Phone Type to Block VOIP

This section explains how to check a phone number’s phone type to determine whether it is VOIP. The sample code provided earlier is broken out into pieces and explained below.

In this code sample, you provide your customer ID and API key to authenticate yourself with TeleSign. Then you create a PhoneIdClient object and use the phoneid method to retrieve information about a phone number you specify. You check to see what phone type code the phone has. You then get a statement saying the phone number is or is not a VOIP phone based on the code. Depending on the result you can add logic to handle either scenario.

  1. Begin by adding statements for including the appropriate part of the TeleSign SDK and any additional language specific functions you may need.
// note change this to the following if using npm package: require('telesignsdk);
const TeleSignSDK = require('../../src/TeleSign');
//var TeleSignSDK = require('telesignsdk');
  1. Insert values for each of the items from customer_id/customerId through 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. 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). 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 portal.telesign.com
const apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="; // Todo: find in portal.telesign.com
const rest_endpoint = "https://rest-api.telesign.com"; // Todo: Enterprise customer, change this!
const timeout = 10*1000; // 10 secs

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

const phoneNumber = "Test phone number with no special characters or spaces goes here.";
  1. Instantiate a PhoneIdClient object containing your customer ID and API key. For node.js, you open a console log here.
console.log("## PhoneIDClient.phoneID ##");
  1. Use PhoneID to check your phone number and store the results of your check in response/telesignResponse. For node.js, you declare a function that will check and store the response that comes from PhoneID.
function messageCallback(error, responseBody) {
    if (error === null) {
        console.log(`PhoneID response for phone number: ${phoneNumber}`
            + ` => code: ${responseBody['status']['code']}`
            + `, description: ${responseBody['status']['description']}`);

        if (responseBody['status']['code'] === 200) {
            if (responseBody['phone_type']['code'] === phoneTypeVOIP) {
                console.log("Phone type in request is VOIP");
            } else {
                console.log("Phone type in request is not VOIP");
            }
        }
    } else {
        console.error("Unable to get PhoneID. " + error);
    }
}
  1. This step checks the phone_type to see what it is. If it returns VOIP, you get a note saying the number is a VOIP phone. Otherwise, you get a note saying it is not a VOIP phone. For node.js, this is where you create a PhoneID client. You pass in the function you defined in the last step.
client.phoneid.phoneID(messageCallback, phoneNumber);
  1. If everything goes well, when you run this code, it submits a phone number you provide to a check by PhoneID. The phone type is returned to you in a response object, which is then checked to see what the phone type is. Depending on results, you will get a note saying the phone type is or is not VOIP.

Code it Without the SDK

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