Receive an Inbound Call

Receiving inbound calls with Nexmo is easy. You just need a server that provides a endpoint that Nexmo will call when your number is called. You configure this endpoint by associating your Nexmo number with an application.

Prerequisites

Implement a webhook

const app = require('express')()
const bodyParser = require('body-parser')

app.use(bodyParser.json())

const onInboundCall = (request, response) => {
  const from = request.query.from || request.body.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)
  .post('/webhooks/answer', onInboundCall)

app.listen(3000)

Run your server

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

$ node app.js

You'll need to expose your server to the open internet. During development you can use a tool like NgrokĀ  to do that.

Associate an application to your webhook

To link your number to the endpoint you've just created we'll need an Application.

$ nexmo app:create demo <YOUR_HOSTNAME>/webhooks/answer <YOUR_HOSTNAME>/webhooks/event
$ nexmo link:app <NEXMO_NUMBER> <NEXMO_APPLICATION_ID>

Call your number

When you call your Nexmo number you should now get a TTS response back.