Add Programmable Voice to Your Node.js Apps with Express

This tutorial explains how to make and receive phone calls with Node.js and the Nexmo Voice API. With Nexmo's Voice API, you can build high-quality programmable voice applications in the cloud and handle tasks such as managing outbound and inbound calls in JSON, recording and storing calls, creating a conference call, sending text-to-speech messages in 23 languages, and so on.

In this tutorial, you will learn how to use the Application and Voice APIs to create a text-to-speech outbound phone call securely and then how to receive inbound calls by implementing a webhook. This tutorial assumes you are working with a Unix or Linux-based operating system such as Mac OS X or Ubuntu.

GitHub icon View the source code on GitHub

Securing Your Nexmo Application

Some of Nexmo's APIs use Nexmo applications, which contain the security and configuration information you need to connect to the Voice API endpoints.

An application:

Figure 1: Using the Nexmo Voice API to call your mobile phone

Figure 1: Using the Nexmo Voice API to call your mobile phone

Creating a Nexmo Application and Generating a Private Key

Your app needs to authenticate requests to the Voice API. In this section, you will generate a private key with the Application API, which allows you to create JSON Web Tokens (JWT) to make the requests.

Begin by creating an application with the Nexmo command-line interface (CLI) tool, which will set up the app and generate a private key for you.

Make sure Node.js 4.0 or above is installed on your machine, then install nexmo-cli from npm:

$ npm install nexmo-cli -g

When you initially signup at Nexmo.com, you will be presented with your Nexmo API key and secret. It will look something like this:

Initial signup at Nexmo.com

This information is also easily retrieved at any time by visiting the settings area of your Nexmo dashboard.

The settings area of the Nexmo dashboard

Next, set up the CLI with your Nexmo API key and secret:

$ nexmo setup API_KEY API_SECRET

For example:

$ nexmo setup aabb11cc fB1234567890abcdefabcde

This will locally save your credentials to a hidden file in your home directory: ~/.nexmorc.

Once configured, you are going to create an application in your working directory using the CLI.

Alex Lakatos Alex Lakatos is a newly minted JavaScript Developer Advocate for Nexmo. In his spare time he volunteers at Mozilla as a Tech Speaker and a Reps Council member. JavaScript developer building on the open web, he has been pushing its boundaries every day.
 

Comments