Using AI/ML for Robocalls handling
By: Alexey Aylarov
Tags: Machine Learning, Robocall, Dialogflow, DIY, Cpaas

Using AI/ML for Robocalls handling

How to create your own Google Call Screening alternative for any phone using Voximplant and Dialogflow Alexey Aylarov Sep 24, 2019·5 min read

Credit: Voximplant

Some of you maybe read or heard about the Call Screening function Google released for its Pixel phones in the United States. The idea itself is very cool — when an inbound call arrives to your phone number, your virtual assistant starts the conversation with a caller, you see the chat on your screen and can intervene at any moment and talk with the caller by yourself. It’s super useful these days when 50%+ of calls are spam, but you don’t want to miss an important call from someone who is not in your contact list. The only problem with it — you can use it only on Pixel phones and only in the United States. Well, the obstacles do exist to overcome them, right? I decided that it’s worth it to explain how to build a similar function using Voximplant and Google Dialogflow. Let’s go!

The architecture

I won’t spend time on explaining what Voximplant is and what Dialogflow is, you can find the information on the internet easily. Let’s describe the idea and the architecture of the solution.

I’ll assume that everybody already has its phone number that is used on a daily basis and we should keep using it for receiving calls we really want to receive. In that case, to build the service like Call Screening we will need to get the 2nd phone number that will be used everywhere — in email, on a business card, when you fill forms somewhere, etc. This 2nd number will be forwarding calls to your main one only in case when you want it, and it will be connected to theNLP system (Dialogflow in our case) for call screening purposes. So the scheme will look as follows:

Now we can implement this service, the only thing we aren’t going to build is a mobile app that will be showing the dialog between our Dialogflow agent and the caller, we will build a very simple web app as proof of the concept and render the dialog there. The app also should have the “Intervene” button, that will tell Voximplant to connect the caller with the callee if the last one decides to talk himself.

Implementation

Log in to the Voximplant control panel at https://manage.voximplant.com/ using your developer account credentials and create a new app, let’s call it “screening”

Open the Numbers section of the control panel at https://manage.voximplant.com/numbers/my_numbers and buy a phone number that will be used as a proxy

Attach the number to the application by clicking the Attach button, use default values for all inputs in the attach form that will appear.

Create a new scenario in the “screening” application and name it myscreening, we will use the code example from the “How to use Dialogflow Connector” article, but we will modify it a little, since we need to get info about the dialog between the caller and our assistant to show it to the callee, you can find the code at https://github.com/aylarov/callscreening/blob/master/voxengine/scenario.js

IMPORTANT: Please note that you will need to change the server variable value to the name of your own ngrok server. And change the line 31 (your phone number = your real mobile number, voximplant number = the one you’ve bought):

outbound_call = VoxEngine.callPSTN(“YOUR PHONE NUMBER”, “VOXIMPLANT NUMBER”)

This code is used for the call transfer function if I decide to intervene and let the caller talk with me.

After you saved the scenario, you need to connect it to the phone number we have bought previously. Open the “Routing” section of the application and create a new rule by clicking the New rule button in the top right corner. Specify some name for the rule (for example, “allcalls”), put .* in the Pattern input (what means that all calls that arrive to our phone number will be processed by the assigned scenarios) and add the scenario to the Assigned scenarios by choosing myscreening in the Available scenarios dropdown.

Save the rule.

Now the phone number is connected to the scenario for processing. The last one thing we need is to connect the bot to the application. Open the Dialogflow connector (in the left menu), click the Add Dialogflow agent button in the top right corner and specify service account JSON file of your Dialogflow agent.

If you need an example of the agent feel free to download it from https://github.com/aylarov/callscreening/tree/master/dialogflow , you can import it in the agent settings. Please don’t expect it to be smart, it’s just an example, you are free to make it better and share you results :)

Simple NodeJS Backend

Let’s deploy the supporting NodeJS backend, you can get it from https://github.com/aylarov/callscreening/tree/master/nodejs

It’s a pretty standard NodeJS app, just run the following commands:

npm install node index.js

The server will be launched at port 3000 on your localhost. We will need to use ngrok to connect Voximplant to it since Voximplant servers are in the cloud. After you install ngrok:

ngrok http 3000

You will see the domain names ngrok assigned to your NodeJS instance on localhost, copy and paste it into the scenario (remember the server variable?)

Client App

The client application looks like a simple chat and available at https://github.com/aylarov/callscreening/tree/master/client

Just copy all the files into some folder on your web server and it should work. In the script.js file change the server variable to your ngrok server name and the callee variable to the phone number you’ve bought previously. Save the file and open the app in the browser. If everything is ok then you should see a successful WebSocket connection in the browser’s console.

Demo

You can see the app in action in the following video.

P.S. If I click the Intervene button the caller will be forwarded to my phone number and if I click the Disconnect — guess what? of course, it will be disconnected.