Skip to content

Instantly share code, notes, and snippets.

@adambutler
Last active April 4, 2018 10:40
Show Gist options
  • Save adambutler/4fc09d29cce8ea9289258ad85cddffae to your computer and use it in GitHub Desktop.
Save adambutler/4fc09d29cce8ea9289258ad85cddffae to your computer and use it in GitHub Desktop.

Make an outbound call

Specification

A building block that shows how to make a simple outbound call & on answer retrive a static NCCO that plays TTS.

  • Change the body of Install the Nexmo library to be appropriate for the language
  • NEXMO_API_KEY must be specified as a constant NEXMO_API_KEY or as a string "NEXMO_API_KEY"
  • NEXMO_API_SECRET must be specified as a constant NEXMO_API_SECRET or as a string "NEXMO_API_SECRET"
  • NEXMO_NUMBER must be specified as a string "NEXMO_NUMBER"
  • TO_NUMBER must be specified as a string "TO_NUMBER"
  • The answer URL must be https://developer.nexmo.com/ncco/tts.json
  • NEXMO_APPLICATION_PRIVATE_KEY must be specified as a constant NEXMO_APPLICATION_PRIVATE_KEY or as a string "NEXMO_APPLICATION_PRIVATE_KEY"
  • 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)

If the library takes a path for the private key:

  • NEXMO_APPLICATION_PRIVATE_KEY_PATH must be specified as a constant

If the library takes string for the private key:

  • NEXMO_APPLICATION_PRIVATE_KEY must be specified

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

Make an outbound call

Making outbound calls from Nexmo is easy. In this building block we'll use the Voice API to start a call and play a text-to-speech message on answer.

Prerequisites

Example

Simply sign up for an account and replace the following variables in the example below:

Key Description
NEXMO_NUMBER Your Nexmo number that the call will be made from. For example 447700900001.
NEXMO_API_KEY You can find this in your account overview
NEXMO_API_SECRET You can find this in your account overview
TO_NUMBER The number you would like to call to in E.164 format. For example 447700900000.

Also you should change one of these two depending on the library you are using:

NEXMO_APPLICATION_PRIVATE_KEY_PATH | The path to your private key file NEXMO_APPLICATION_PRIVATE_KEY | A string of your private key

Install the Nexmo library

$ npm install --save nexmo

Initialize the library

// GITHUB: https://github.com/nexmo-community/nexmo-node-quickstart/blob/master/voice/make-call.js
// Lines: 11-18

const Nexmo = require('nexmo')

const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET,
  applicationId: NEXMO_APPLICATION_ID,
  privateKey: NEXMO_APPLICATION_PRIVATE_KEY_PATH
})

Send an SMS

// GITHUB: https://github.com/nexmo-community/nexmo-node-quickstart/blob/master/sms/send.js
// Lines: 17-21

nexmo.calls.create({
  to: [{
    type: 'phone',
    number: NEXMO_TO_NUMBER
  }],
  from: {
    type: 'phone',
    number: NEXMO_FROM_NUMBER
  },
  answer_url: ['https://developer.nexmo.com/ncco/tts.json']
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment