Rate this page:

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:

Key-value store scheme

Let us see how to build this solution.

Prerequisites

Copy URL
  1. Create an application.
  2. Create a scenario.
  3. Create a routing rule and attach it to the scenario.
  4. Rent a phone number and attach it to the routing rule. This is the phone number a courier or a customer calls.
  5. Rent phone numbers for the courier, the customer and the agent. For a test scenario, you can omit the agent.

Scenario setup

Copy URL

For this article, we provide a fully working scenario example. Feel free to copy and paste it into your scenario:

Full scenario code

Full scenario code

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

Copy URL

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.

Enter the order number

Enter the order number

If the caller enters #, connect the call to an agent:

Transfer to an agent

Transfer to an agent

If they enter a 5-digit number, call the handleInput method:

Call handleInput

Call handleInput

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:

Compare the order numbers

Compare the order numbers

If the order is found, get the courier and customer phone numbers connected with it:

Get the phone numbers

Get the phone numbers

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:

Define a caller

Define a caller

If the number is not in the store, ask a caller to call again from the number they use to place the order:

Undefined phone number

Undefined phone number

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:

Undefined order number

Undefined order number

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:

Make a call

Make a call

At the same time, tell the callee that the call is about clarification of information on the order:

Talk to the callee

Talk to the callee

Then, handle the disconnect event:

Handle the disconnect event

Handle the disconnect event

Notify the caller if the callee is unavailable:

Callee is unavailable

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:

Choose a TTS provider

Choose a TTS provider

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

Copy URL

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.

  1. Go to your project folder and install the SDK via pip: python -m pip install --user voximplant-apiclient

  2. Create a .py file with the code that adds the order details to the key-value store via the set_key_value_item method:

Add order details

Add order details

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.

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

Copy URL

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.