Get Started with Number Masking using .NET

    Overview

    Phone number masking is the process of establishing a call between two parties without revealing their contact information. Many businesses often require a technique to anonymize communication between two parties involved on the platform, for example, a customer and a delivery agent on a food delivery service platform. This technique involves an intermediate phone number that acts as a proxy between the two parties on the call. In this guide, we will walk you through the implementation of number masking with the help of a Plivo number which will act as the intermediate number to connect both the parties on a call anonymously.

    Outline

    Implementation

    In this example, we will build a number masking application for a food delivery service. Through this implementation, the company can connect the customers with the delivery agents and vice versa without revealing their actual phone numbers.

    Following are the steps involved in the implementation phase:

    1. Create a Customer<->Agent phone number mapping in your application backend
    2. Create the number masking application using the Plivo Voice platform.
    3. Assign the number masking app to a Plivo number.

    Set Up Your .NET Dev Environment

    In this section, we’ll walk you through how to set up a .NET Framework app in under five minutes and start handling incoming calls & callbacks.

    Install .NET Framework

    You must set up and install Dotnet Framework(.NET Framework 4.6 or higher) and Plivo’s Dotnet SDK to receive incoming calls. Here’s how.

    Operating SystemInstructions
    OS X & LinuxTo see if you already have Dotnet Framework installed, run the command dotnet --version in the terminal. If you do not have it installed, you can install it from here.
    WindowsTo install Dotnet Framework on Windows follow the instructions listed here.

    Install Plivo .NET Package using Visual Studio

    • Create a MVC web app:

    Create a MVC app

    • Configure the MVC app and provide a project name:

    Configure the MVC app

    • Install the Plivo Nuget package

    Install Plivo Nuget Package

    Create a 1:1 map with actual numbers

    • Whenever a customer places an order, the customer’s phone number is stored on your app’s database.
    • A delivery executive will be assigned for that order, and the agent’s number is also stored on your database and mapped with the customer’s number. For example,
        Customer's Number		<->		Agent's Number
        1-415-666-7777					1-415-666-7778
      
    • In this guide, we have created a sample mapping data in App.config like below:
        <?xml version="1.0" encoding="UTF-8" ?>
        <configuration>
            <configSections>
                <section
                        name="CustomerAgent"
                        type="System.Configuration.DictionarySectionHandler" />
            </configSections>
            <CustomerAgent>
                <add key="14156667777" value="14156667778" />
                <add key="14156667779" value="14156667780" />
                <add key="14156667781" value="14156667782" />
            </CustomerAgent>
        </configuration>
      

    Create a MVC Controller for Number Masking

    Navigate to Controllers directory in “NumberMasking” app and create a Controller named HandleIncomingController.cs paste the following code.

    Create a MVC Controller

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    
    using System.Configuration;
    using Plivo.XML;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.AspNetCore.Mvc;
    using System.Diagnostics;
    using System.Collections;
    
    // Handle incoming calls to a Plivo number, connect agent with customer and vice versa without revealing their actual phone numbers. 
    
    namespace NumberMasking.Controllers
    {
        public class HandleIncomingController : Controller
        {
    
            // GET: /<controller>/
            public IActionResult Index()
            {
                string FromNumber = Request.Query["From"];
                string ToNumber = Request.Query["To"];
                var resp = new Response();
    
                // Customer <> Agent Mapping
                var CustomerAgentMap = (ConfigurationManager.GetSection("CustomerAgent") as Hashtable)
                     .Cast<DictionaryEntry>()
                     .ToDictionary(n => n.Key.ToString(), n => n.Value.ToString());
    
                // Agent <> Customer Mapping
                var AgentCustomerMap = CustomerAgentMap.ToDictionary(kp => kp.Value, kp => kp.Key);
    
                if (CustomerAgentMap.ContainsKey(FromNumber)) // To check if the Customer's number is existing in the Customer-Agent mapping
                {
                    var DestNumber = CustomerAgentMap[FromNumber]; // This will assign the Value from the customer-agent array to number variable
    
                    Dial dial = new Dial(new
                        Dictionary<string, string>() {
                        {"callerId", ToNumber} // Plivo number will be used as the caller ID for the call towards Agent
                    });
                    dial.AddNumber(DestNumber,
                        new Dictionary<string, string>() { });
                    resp.Add(dial);
                }
                else if (AgentCustomerMap.ContainsKey(FromNumber)) // To check if the Agent's number is existing in the Customer-Agent mapping
                {
                    var DestNumber = AgentCustomerMap[FromNumber]; // This will assign the Key from the customer-agent array to number variable
                    Dial dial = new Dial(new
                        Dictionary<string, string>() {
                        {"callerId", ToNumber} // Plivo number will be used as the caller ID for the call towards Customer
                    });
                    dial.AddNumber(DestNumber,
                        new Dictionary<string, string>() { });
                    resp.Add(dial);
                }
                Debug.WriteLine(resp.ToString());
                var output = resp.ToString();
                return this.Content(output, "text/xml");
            }
    
        }
    }
    

    Before starting the app, you have to update Properties/launchSettings.json by setting the applicationUrl as

        "applicationUrl": "http://localhost:5000/"
    

    Run the project and you should see your basic server app in action on http://localhost:5000/handleincoming/.

    Exposing your local server to the internet

    To receive Incoming Calls and to handle callbacks, your local server should be able to connect with Plivo API service, Ngrok is a tunneling software used to expose a web server running on your local machine to the internet. Using Ngrok you can set webhooks which can talk to Plivo server.

    ngrok block diagram

    You can download and install ngrok from here. Follow the detailed configuration instructions to get started.

    Run ngrok on the port which currently hosts your application. For example, if your port number is 5000, run the following command:

    ./ngrok http 5000
    

    This will give you a UI with links that look like ngrok.io/* which you can use to access your local server using the public network.

    Sample ngrok CLI

    • If the incoming call to your Plivo number is from one of the phone numbers of the customer in the Customer <-> Agent Map, for example, if the caller number is “14156667777” then the XML response to process the incoming call will be as below, you can check the XML document in your browser.

      XML Document - Customer Calls Agent

    • If the incoming call to your Plivo number is from one of the phone numbers of the agent in the Customer <-> Agent Map, for example, if the caller number is “14156667778” then the XML response to process the incoming call will be as below, you can check the XML document in your browser.

      XML Document - Agent Calls Customer

    Create a Plivo Application

    1. Create an Application by visiting the Application Page and click on New Application or by using Plivo’s Application API.
    2. Give your application a name. Let’s call it Phone IVR. Enter your server URL (e.g., https://61d8fb8f250c.ngrok.io/handleincoming/) in the Answer URL field and set the method as GET. See our Application API docs to learn how to modify your application through our APIs.
    3. Click on Create to save your application.

      Create Application - Number Masking

    Assign a Plivo number to your app

    1. Navigate to the Numbers page and select the phone number you want to use for this app.
    2. Select Phone IVR (name of the app) from the Plivo App dropdown list.
    3. Click on ‘Update Number’ to save.

      Assign Application - Number Masking

    Test and validate

    To test how “Number Masking” works, you need two mobile numbers. You can set one of your mobile numbers as a customer and another one as an agent in the customer: agent mapping data in the config file and make a call to your Plivo phone number. If you call from “mobile number 1” to the Plivo number, you will see that the call is forwarded to your “mobile number2” with the Plivo number as the caller ID. The same setup will work for calls from “mobile number2” to “mobile number1” with the Plivo number as the caller ID.