How to Make a Private Phone Call with Node.js
Published on November 6, 2020

This is the fourth tutorial in the "Getting Started with Vonage Voice APIs and Node.js" series, which followed our Getting Started series on SMS APIs. See links to prior tutorials in these series at the bottom of the post.

The previous installments in this series showed how to make an outbound text-to-voice a call, handle inbound calls, and record the calls. This one explains how to use the Nexmo Call Control Object again to make anonymous calls.

View the source code proxy-call.js GitHub

Proxy-Call Scenarios

There are real-life scenarios where two parties want to communicate without letting each other know their real phone numbers. Take communication between a ride-share service driver and the passenger or a matched pair on a dating app, for example. This tutorial walks through a related but much simpler scenario: forwarding a temporary phone number to a real phone, using a Vonage virtual phone number as a proxy.

Let’s say you are building a classified ads app, which connects a seller and a potential buyer. The buyer calls a proxy phone number from the app to connect to her real phone number, so she can have a conversation with the buyer without either of them knowing the other’s number.

Vonage Proxy CallVonage Proxy Call

Setting up an Application and Webhook Endpoints

To make your webhooks work, let’s set up and run **ngrok** (as in prior tutorials in the series) :

You are going to use the forwarding URL, which looks like this https://18627fc4.ngrok.io, as your temporary webhook endpoints during development.

Let’s create a new Vonage Application with the ngrok URLs.

Then associate your Vonage virtual phone number (which is used as a proxy number) with the Application:

When the linking is successful, the CLI returns the message, "Number updated".

Now, let’s run an Express server and create a scaffold of the webhooks, as in previous tutorials. Use the same route name as you specified when you created the Application:

Using a Vonage Call Control Objects to Forward a Call

Prior tutorials used the [Nexmo Call Control Object] (https://docs.nexmo.com/voice/voice-api/ncco-reference) (NCCO) for a variety of purposes, such as answering a call and recording a call. This time, we are using the `connect` feature to connect two phone numbers.

Use the NCCO within the /proxy-call webhook:

In actual app development, you probably want to look up your customers’ real phone numbers from a database. For demonstration purposes, let’s pretend that the SELLER_NUMBER is coming from your DB for your app, and just hard-code your test phone number to work with this tutorial.

Now, run the node script.

If you have another phone number (that is not the one you used in the NCCO as the SELLER_NUMBER), assume the role of the buyer and call your Vonage virtual phone number.

If everything is working as expected, the "buyer" call is forwarded to the “seller” number without revealing either party’s phone number!

For Real Applications

Each Getting Started Guide installment shows how to use a Vonage API to fulfill only a certain scenario. The guide does not provide all of the solutions for your production applications. In reality, you will develop with multiple APIs to build a complete solution.

For example, if you are building a real-life ride-share application where a driver and a rider can communicate anonymously, you should also look at incoming calls from the driver, as well as determine the rider’s virtual number to connect. Also, it would be a good idea to send SMS messages to the private numbers.

API References and Tools

Vonage Getting Started Guide for Node.js

Tomomi ImuraVonage Alumni

Open web & technology ? HTML5, JavaScript, Node.js. Cat hacks ?, and Internet of Blings ✨ (that slightly more than LED blinks ?). Former Developer Advocate at Vonage, San Francisco.

Ready to start building?

Experience seamless connectivity, real-time messaging, and crystal-clear voice and video calls-all at your fingertips.

Subscribe to Our Developer Newsletter

Subscribe to our monthly newsletter to receive our latest updates on tutorials, releases, and events. No spam.