Receive an inbound call

This code snippet demonstrates how to receive an inbound call on your Smart Number.

Prerequisites

Create an Application

Go to the Application's page on the Dashboard, and define a Name for your Application.

An example of brand new application

Make sure to click on the Generate public and private key button, and keep the file private.key around.

Then, enable the Voice capability. For the moment, leave everything by default.

An example of enabling Voice capabilities

Finally, click Generate new application at the bottom of the page.

Install dependencies

npm install express

Initialize your dependencies

Create a file named receive-an-inbound-call.js and add the following code:

const app = require('express')()

Write the code

Add the following to receive-an-inbound-call.js:

const onInboundCall = (request, response) => {
  const from = request.query.from
  const fromSplitIntoCharacters = from.split('').join(' ')

  const ncco = [{
    action: 'talk',
    text: `Thank you for calling from ${fromSplitIntoCharacters}`
  }]

  response.json(ncco)
}

app.get('/webhooks/answer', onInboundCall)

Try it out

Save the file to your machine and run it using the following command:

node receive-an-inbound-call.js

When you call your Smart Number you will hear a text-to-speech message.