Get Started with the SMS Verify SDK
This tutorial teaches you how to use the SMS Verify SDK, by walking you step-by-step through the creation of an integration where you send your own verification code to an end-user. Skip to the end of this page to see the full, completed sample code.
This tutorial includes CLI examples using a bash shell in Mac Terminal, please modify accordingly if you are using a different system.
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.
This tutorial uses Python 3.8.1. Please modify accordingly if you are using a different version of Python.
Step 1: Download the SDK
- Create a directory on your machine where you want to download the TeleSign Python SDK. This should not be in the same directory as where you build your integration.
cd ~/code/local mkdir telesign_sdks cd telesign_sdks
- In the new directory you created, clone the SDK from GitHub. A new directory should appear called
git clone https://github.com/TeleSign/python_telesign_enterprise.git
Step 2: Create Code to Send the SMS
- Create another directory (must be outside of the SDK directory you just created) where you want your SMS Verify integration to go.
cd ~/code/local/telesign_integrations mkdir sms_verify_integration cd sms_verify_integration
- Install the SDK in this new directory using the CLI command below. It references the path to where you downloaded the SDK. Once the SDK is installed, you should see
Successfully installed telesignenterprisein the terminal:
pip install -e ~/code/local/telesign_sdks/python_telesign_enterprise/
- Create a new file in your integration folder called
verify_with_own_code.pyand open it in your editor:
- Add code to import dependencies from the TeleSign SDK:
from telesignenterprise.verify import VerifyClient from telesign.util import random_with_n_digits
- Define variables to store your authentication credentials:
customer_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890" api_key = "TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
- Define a variable to hold the end-user’s phone number you want to send verification to. For this tutorial, hardcode the phone number to one for a device you can use for testing:
phone_number = "15558675309"
In your production integration, have
phone_number pull from your recipient database instead of hardcoding it.
- Randomly generate your verification code. We will use a TeleSign SDK utility for this. The parameter value
5specifies the number of digits generated:
verify_code = random_with_n_digits(5)
- Instantiate a verification object with your authentication credentials.
verify = VerifyClient(customer_id, api_key)
- Send a verification SMS to the end-user and store the response. Behind the scenes, this sends an HTTP request to the TeleSign SMS Verify API. TeleSign then sends an SMS with the code to the end-user:
response = verify.sms(phone_number, verify_code=verify_code)
- Collect the potential verification code entered by the end-user in your application. In this tutorial, we will simulate this by prompting for input from the command line.
user_entered_verify_code = input("Please enter the verification code you were sent: ")
In your production implementation, you will listen for input from your website or other application where the end-user is trying to log in.
- Determine if the user-entered code matches your verification code, and resolve the login attempt accordingly. In this tutorial, we just report whether the codes match.
if verify_code == user_entered_verify_code.strip(): print("Your code is correct.") else: print("Your code is incorrect.")
In your production implementation, you will add code here to log the user in when the codes match.
Step 3: Test Your Integration
- Switch from your editor to the terminal and run
- You should receive an SMS on your phone that looks like this:
- In the terminal, you should see a prompt to enter a code. Enter the code from your phone to test a successful verification:
Please enter the verification code you were sent: 82139 Your code is correct.
- Now let’s test an unsuccessful verification. Run
- You should receive a new and different SMS code on your phone. Enter something else though in the command prompt, and you should get a message that verification failed.
Please enter the verification code you were sent: 55555 Your code is incorrect.
Here is the complete sample code for this tutorial:
from telesignenterprise.verify import VerifyClient from telesign.util import random_with_n_digits customer_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890" api_key = "TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==" phone_number = "15558675309" verify_code = random_with_n_digits(5) verify = VerifyClient(customer_id, api_key) response = verify.sms(phone_number, verify_code=verify_code) user_entered_verify_code = input("Please enter the verification code you were sent: ") if verify_code == user_entered_verify_code.strip(): print("Your code is correct.") else: print("Your code is incorrect.")