Phone number masking
In this article, you will learn how to create a solution to mask phone numbers with Voximplant's key-value storage.
In this solution, a customer and a courier can call each other without knowing each other's phone numbers. Instead, they call a rented Voximplant number and use, for example, an order number to connect to each other.
If a courier calls and enters the order number, and it exists in the application database, the scenario connects the call to the customer. If the customer calls the same number and enters the same order number, the scenario connects the call to the courier. If someone calls from a number that is not in the database, the system asks to call from a number that they use to make the order.
The whole scheme looks like this:
Let us see how to build this solution.
Prerequisites
- Create an application.
- Create a scenario.
- Create a routing rule and attach it to the scenario.
- Rent a phone number and attach it to the routing rule. This is the phone number a courier or a customer calls.
- Rent phone numbers for the courier, the customer and the agent. For a test scenario, you can omit the agent.
Scenario setup
For this article, we provide a fully working scenario example. Feel free to copy and paste it into your scenario:
After you paste this code to your scenario, change the phone number you use as the caller ID to the number you rent for this application in the store
variable, and it is ready to use.
Code explanation
This section explains some difficult parts of the scenario code for better understanding.
Enter the order number
When a call arrives, ask a caller to enter the order number and handle it via the dtmfHandler function.
If the caller enters #, connect the call to an agent:
If they enter a 5-digit number, call the handleInput method:
Search the order
Compare the entered number with order numbers in the store via the ApplicationStorage.get() method and use the entered number as a key:
If the order is found, get the courier and customer phone numbers connected with it:
If the caller’s number is the courier’s, forward a call to the customer, if it is the customer’s – to the courier. The callCourierOrClient function is intended for this:
If the number is not in the store, ask a caller to call again from the number they use to place the order:
Handle what happens when the order number is not in the store. In such a case, ask the caller to make sure the number is correct and enter it again:
Call the customer or courier
In the callCourierOrClient function, tell the caller that you transfer the call to the courier/client and play music for hold. Use the callPSTN method to call the client or the courier:
At the same time, tell the callee that the call is about clarification of information on the order:
Then, handle the disconnect event:
Notify the caller if the callee is unavailable:
The say method is responsible for all the phrases the robot utters. The phrases themselves are in the phrases associative array. Choose a TTS provider and a voice in the list of Voximplant TTS providers:
This scenario also records the calls via the record method and enables you to save statistics to the database (sendResultToDb). It allows you to analyze statistics, provide quality control, and quickly resolve any issues that might arise during the delivery process.
Key-value store
The scenario works properly if the key-value store is not empty. Use the management API to operate key-value storage. In this example, we use a Python API client. It requires Python 2.x or 3.x with pip and setuptools >= 18.5 installed.
Go to your project folder and install the SDK via pip:
python -m pip install --user voximplant-apiclient
Create a .py file with the code that adds the order details to the key-value store via the set_key_value_item method:
You can generate a credentials.json file when creating a service account in the Service accounts section. Choose a role that allows you to call the set_key_value_item method (e.g. Owner).
Find the APPLICATION_ID in the address bar when navigating to your app.
In this example, we use a five-digit order number as a key (KEY) and phone numbers as values. TTL here is to specify the values storage period.
- Run the file to save the order details:
python kvs.py
In case you no longer want a client and a courier to disturb each other, you can delete the order details from the store. Find all the available key-value store methods in our documentation: management API and VoxEngine.
Test the app
Call from the customer's or courier's phone number to the number rented in the panel. Then enter the order number (in our case, it is 12345) and wait for the connection with the other party.
If everything is correct, the customer and the courier can call each other and discuss the details of the order without knowing each other's personal numbers, and thus without any privacy issues.