Phone ID - Tutorial: Use Contact Match with Telesign Node.js SDK
NOTE:
To add Contact Match to your account, contact a Telesign expert. This feature is available for full-service accounts only.
This tutorial describes how to use the Phone ID Contact Match identity attribute with the Telesign Node.js SDK, guiding you step-by-step through the creation of an integration that uses the Phone ID Contact Match. Skip to the end of this page to see the full sample code.
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.
- Identity attribute enabled - Make sure the Contact Match identity attribute is enabled by Telesign. If it is not yet enabled, contact a Telesign expert.
- Phone number - The phone number you want to get information about.
NOTE:
This tutorial uses the following:
- MacOS
- Node v16.9.0
Please modify accordingly if your developer environment differs from these details.
Set up your project
-
Follow the Telesign Full-service Node.js SDK install instructions here on GitHub incorporating these details:
- Use
phone_id
as the project name.
- Use
-
Create a new file called
phone_id_contact_match.js
and open it in your editor.touch phone_id_contact_match.js
You should end up in the top-level directory for your project in the Terminal.
Make a Contact Match request
-
Follow the steps below or copy the sample code into the file and update accordingly.
-
Add this import. The
telesignenterprisesdk
import refers to the Telesign Full-service SDK.const TelesignSDK = require('telesignsdk');
-
Define variables to store your authentication credentials.
const customerId = process.env.CUSTOMER_ID || "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"; const apiKey = process.env.API_KEY || "ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";
-
Define a variable to hold the phone number you want to get information for. This should be a string with no spaces or special characters. Use the complete number, including the country code. For example:
16505551212
.const phoneNumber = process.env.PHONE_NUMBER || "11234567890";
NOTE:
In your production integration, pull the phone number from your recipient database instead of hardcoding it.
-
Define variables to hold the first name and last name that you want to match.
const firstName = 'The first name you want to match for goes here.'; const lastName = 'The last name you want to match for goes here.';
-
Instantiate a Phone ID client object containing your Customer ID and API Key.
const client = new TelesignSDK(customerId, apiKey);
-
Define a callback function to output the body of the response in the console for debugging purposes.
function callback (error, data) { if (error === null) { console.log(`PhoneID response for phone number: ${phoneNumber} ` + `=> code: ${data['status']['code']}, ` + `description: ${data['status']['description']}`); if (data['contact_match']['status']['code'] === 2800) { console.log( `Contact match scored first name ${data['contact_match']['first_name_score']} and scored` + `last name ${data['contact_match']['last_name_score']}.`); } else { console.log(`Contact match did not run successfully: ${data['contact_match']['status']['description']}`) } } else { console.error(`Unable to get PhoneID. ${error}`); } }
-
Store the object, and pass it your phone number then pass the identity attribute,
contact_match
, that you want to use.client.phoneid.phoneID(callback, phoneNumber, { addons: { contact_match: { first_name: firstName, last_name: lastName } } });
Test your integration
-
Switch from your editor to the terminal and run:
node phone_id_contact_match.js
Sample code
const TelesignSDK = require('telesignsdk');
const customerId = process.env.CUSTOMER_ID || "FFFFFFFF-EEEE-DDDD-1234-AB1234567890";
const apiKey = process.env.API_KEY || "ABC12345yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";
const phoneNumber = process.env.PHONE_NUMBER || "11234567890";
const firstName = 'The first name you want to match for goes here.';
const lastName = 'The last name you want to match for goes here.';
const client = new TelesignSDK(customerId, apiKey);
function callback (error, data) {
if (error === null) {
console.log(`PhoneID response for phone number: ${phoneNumber} ` +
`=> code: ${data['status']['code']}, ` +
`description: ${data['status']['description']}`);
if (data['contact_match']['status']['code'] === 2800) {
console.log(
`Contact match scored first name ${data['contact_match']['first_name_score']} and scored` +
`last name ${data['contact_match']['last_name_score']}.`);
} else {
console.log(`Contact match did not run successfully: ${data['contact_match']['status']['description']}`)
}
} else {
console.error(`Unable to get PhoneID. ${error}`);
}
}
client.phoneid.phoneID(callback, phoneNumber, {
addons: {
contact_match: {
first_name: firstName,
last_name: lastName
}
}
});
Updated about 14 hours ago