SIGN UP

Phone Number Masking

Phone Number Masking

INTRODUCTION

How often did you consider masking your private phone number? At first, this question may seem odd but imagine the situation when you order a taxi and, after the trip, the driver starts calling you. That’s not what you normally expect from a taxi service, right? The same is true for the driver: it wouldn’t be great if previous customers would call and distract the driver on the ride or (even worse) on vacation.

First, having a delicate distance between yourself and service workers is much better than having no distance at all. Second, it is important that both parties have the fastest way to contact each other. The Voximplant cloud can easily address these requirements with a phone number masking approach. This article will guide you through all the necessary steps to implement this feature for a simplified case of a single driver and a few customers. Note that this solution is scalable for any number of drivers and customers.

 

WHAT YOU NEED

To implement the solution, you will need:

  • Voximplant developer account. If you don’t have one, sign up here.
  • A simple backend. We will use the node.js server.
  • A phone number that is purchased from Voximplant. It will be our “call center” number. We will use a “virtual” phone number for demonstration.
  • A JS scenario. It will be created during this tutorial.

 

1. BACKEND

To get things done quickly, we suggest using the Express framework for node.js.

Install node.js and express.js on any server platform (AWS, Azure, or any VDS etc.). You can also test the solution locally using ngrok, which allows testing demo applications without deploying them.

Then create the index.js file with the following code:

const express = require('express');
const app = express();
 
app.use(express.urlencoded());
app.use(express.json());
 
let lastCustomerNumber = null;
app.post('/', (req, res) => {
  lastCustomerNumber = req.body.customerNumber;
  res.sendStatus(200);
});
app.get('/', (req, res) => {
  res.send(lastCustomerNumber);
});
app.listen(3000);

Now we have the backend server that could store and give the number of the last caller (customer). Note that we use different request methods for saving/giving.

2. PHONE NUMBER

In the VoxImplant control panel, on the top menu, select Phone numbers and then click Buy new phone number in the drop-down list.

dropdown

The Available numbers page will be displayed. Click the Real number switch to change it to Test number. Then click Buy to buy a virtual phone number.

3. JS SCENARIO AND APPLICATION

As was mentioned above, our example includes only one driver, that’s why this number won’t be changed. Therefore we can save the driver’s number right in the JS scenario for demonstration purpose.

For every incoming call, we need to check the caller’s number:

  1. If the incoming call number doesn’t match the driver’s number, we will save this number to the backend, call the driver and establish a connection with the customer.
  2. If the incoming call number matches the driver’s number, we will retrieve the last customer’s number from the backend, call the customer and establish a connection with the driver

The logic is simple but effective in our context. Let’s see how to implement this logic in the Voximplant JS scenario. Pay attention to the callPSTN method call, the second argument should be the number you bought (see paragraph 2).

VoxEngine.addEventListener(AppEvents.CallAlerting, (e) => {
  const driverNumber = "123456789";  // hardcoded for demonstration purposes
  const incNumber = e.callerid.trim();  // save the incoming call number and remove possible spaces
  const inc = e.call;
 
  // check if the incoming call number belongs to the customer
  if(incNumber !== driverNumber) { 
    const out = VoxEngine.callPSTN(driverNumber, "123456789");  // make an outbound call to the driver
    VoxEngine.easyProcess(inc, out);  // establish a connection between the driver and the customer
 
    // make a POST request to the backend to save the customer’s number
    const test = Net.httpRequest("http://yourbackend.server/", () => {},
                    {headers:["Content-Type: application/json;charset=utf-8"],
                     method: "POST",
                     postData: JSON.stringify({'customerNumber': incNumber})
                    });
  } else {  // if the incoming number belongs to the driver
    // make a GET request to the backend to retrieve the customer’s number
    Net.httpRequest("http://yourbackend.server/", (e) => {
      if (e.code === 200) {
        const customerNumber = e.text;
        if (customerNumber == undefined) {  // if the server has no customer number
          inc.startEarlyMedia();
          // say a phrase to the driver and finish the call
          inc.say("Sorry, you have no passengers yet", Language.US_ENGLISH_FEMALE);
          inc.addEventListener(CallEvents.PlaybackFinished, VoxEngine.terminate);
        } else {
          const out = VoxEngine.callPSTN(customerNumber, "123456789");  // make an outbound call to the customer
          VoxEngine.easyProcess(inc, out);  // establish a connection between the customer and the driver
        }   
      }
    });
  } 
});

That’s it! To create the scenario, go to the Scenarios tab of the VoxImplant control panel and add the scenario with the code above. Let’s name it call-handling.

The actions that are shown in VoxImplant control panel (GUI) could also be performed via HTTP API. For example, you can add the new application using the /AddApplication method.

As you might know, there is an Applications concept in Voximplant. The Applications allow linking scenarios, phone numbers, users, and call queues. Even if there’s only one scenario, we need to create an application because the phone numbers and scenarios are linked via applications. Go to the Applications tab, click Create application, type the name of a new application (“Taxi”, for example) and then click Create.

application

Then add a new rule to your Taxi application; you can name it Incoming call. Use the created JS scenario in the rule and leave the default call pattern ( .* ).

rule

For more information about rules and applications, see the corresponding articles:

Your first VoxImplant application

Handling an incoming call

4. NUMBER + APPLICATION + RULE

Finally, go to the My phone numbers tab, locate your number and select the Taxi application with the Incoming call rule in the drop-down list next to your phone number. Click the tick button to save changes.

phone-number

Well done! We’ve just linked the phone number to the JS scenario! Actually, our solution is ready to serve customers.

5. HOW TO USE THE DEMO

First of all, start your backend server. As our backend initially has no customer number, it would be better if a customer made the first call.

When a customer calls the purchased number, our cloud receives the call and executes the JS scenario to handle it. According to the JS scenario:

  • The customer’s number will be saved to the backend.
  • The cloud will call the driver.
  • When the driver answers the call, a connection to the customer will be established.

 

Since the backend now stores the customer number, the driver can call the customer. The driver calls the purchased number and the JS scenario causes the  following to happen:

  • The cloud requests the customer number from the backend.
  • If the backend successfully returns the customer number, the cloud will call the customer.
  • When the customer answers the call, a connection to the driver will be established.

6. NEXT STEPS

This demo is pretty simple but represents the general idea of phone number masking. There’s no magic but the power of cloud telephony. The described approach allows you to create safe, convenient, and – what’s  hugely important – scalable solutions. Add the additional checks in the scenario, make the cloud play music while establishing a connection, build a sophisticated backend structure, etc. Do whatever you need to provide the best service. Make the machine suffer for the sake of satisfied customers! 

 

Tags:number masking
B6A24216-9891-45D1-9D1D-E7359CEB8282 Created with sketchtool.

Comments(0)

Add your comment

To leave a comment, first confirm that you are not a robot. It's free

Recommend

Get your free developer account or talk with our sales team to learn more about Voximplant solutions
SIGN UP
Contact sales

Please complete this field.

Please complete this field.

Please complete this field.

Choose the solution

Please complete this field.

Please complete this field.