How to Record Phone Calls in Node.js


Incoming Voice

While it might be fun to program a robot to answer a physical phone, Twilio makes answering a phone call as easy as responding to an HTTP request. When a phone number you have bought through Twilio receives an incoming call, Twilio will send an HTTP request to a server you control, asking for instructions on how to handle the call. Your server will respond with an XML document containing TwiML that tells Twilio to read out a message, play an MP3 file, make a recording, and much more.

To start answering phone calls, you must:

  • Buy and configure a Twilio-powered phone number capable of making and receiving phone calls, and point it at your web application
  • Write web application code to tell Twilio how to handle the incoming call (using TwiML)
  • Make your web application accessible on the Internet so Twilio can send you a webhook request when you receive a call

Buy and configure a phone number

In the console, you can search for and buy phone numbers in dozens of different countries, capable of calling (and being called by) just about every phone on the planet.

Search for voice capable numbers

Once you purchase a number, you'll need to configure that number to send a request to your web application. This callback mechanism is called a webhook. This can be done in the number's configuration page.

configure an incoming phone number URL

What's a Webhook?

A webhook is a callback mechanism that allows two systems to communicate events to one another over the Internet using HTTP requests. In this case, Twilio is sending a webhook request to your web application whenever a phone number you control receives an incoming call. You'll see this webhook mechanism used in many Twilio APIs for handling event notifications like this.

Not working on a server with a public URL? We'll show you how to expose your local development machine to the public Internet later in this guide. Next, you'll need to write some server-side code that will be executed when an incoming call comes in.