Skip to content

Instantly share code, notes, and snippets.

@adambutler
Last active March 9, 2018 17:02
Show Gist options
  • Save adambutler/85bf06bb443ff3795195d500a6d55ce6 to your computer and use it in GitHub Desktop.
Save adambutler/85bf06bb443ff3795195d500a6d55ce6 to your computer and use it in GitHub Desktop.

Receive an Inbound Call

Specification

A building block that shows how to handle an inbound call

  • You must specify one endpoint must be on the path /webhooks/answer

  • Your endpoint must be accessible a GET request

  • Your endpoint must listen on port 3000

  • Your response should return a 200 status code

  • Your endpoint should handle query string parameters

  • Your response should be JSON NCCO with the the following or equivilent body:

    • GET + Query

      curl "http://127.0.0.1:3000/webhooks/answer?from=447700900000"

Should return:

[
  {
    "action": "talk",
    "text": "Thank you for calling from 4 4 7 7 0 0 9 0 0 0 0 0"
  }
]
  • Code examples should include a GitHub link to the file
  • Code examples should include the line numbers used from the linked file
  • All code examples must be present in the master branch of the relevant quickstart repo
  • All code examples must be tested to work (manual testing is fine)

Instructions

  1. Fork this gist
  2. Edit the gist and the building block files to match the specification
  3. Return Gist as a comment in the original issue

Receive an Inbound Call

Reciving inbound calls with Nexmo is easy. You just need to provide a webhook endpoint and configure an application to point to it.

Prerequisites

Implement a webhook

// GITHUB: https://github.com/nexmo-community/nexmo-node-quickstart/blob/master/voice/receive-an-inbound-call.js
// Lines: ALL LINES

const app = require('express')()

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)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment