Make an outbound call

This building block makes an outbound call and plays a text-to-speech message when the call is answered.

Example

Replace the following variables in the example code:

Key Description
NEXMO_NUMBER Your Nexmo number that the call will be made from. For example 447700900000.
TO_NUMBER The number you would like to call to in E.164 format. For example 447700900001.

Prerequisites

Create an application

Write the code

Add the following to make-an-outbound-call.sh:

Copy to Clipboard
curl -X POST https://api.nexmo.com/v1/calls\
  -H "Authorization: Bearer "$JWT\
  -H "Content-Type: application/json"\
  -d '{"to":[{"type": "phone","number": "'$TO_NUMBER'"}],
      "from": {"type": "phone","number": "'$NEXMO_NUMBER'"},
      "answer_url":["https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json"]}'

View full source 

Run your code

Save this file to your machine and run it:

$ bash make-an-outbound-call.sh

Prerequisites

Create an application

Install dependencies

Initialize your dependencies

Write the code

Add the following to app.js:

Copy to Clipboard
nexmo.calls.create({
  to: [{
    type: 'phone',
    number: TO_NUMBER
  }],
  from: {
    type: 'phone',
    number: NEXMO_NUMBER
  },
  answer_url: ['https://developer.nexmo.com/ncco/tts.json']
})

View full source 

Run your code

Save this file to your machine and run it:

$ node app.js

Prerequisites

Create an application

Install dependencies

Initialize your dependencies

Write the code

Add the following to OutboundTextToSpeech.java:

Copy to Clipboard
nexmo.getVoiceClient().createCall(new Call(TO_NUMBER, NEXMO_NUMBER, ANSWER_URL));

View full source 

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following command to execute your application replacing com.nexmo.quickstart.voice with the package containing OutboundTextToSpeech:

gradle run -Pmain=com.nexmo.quickstart.voice.OutboundTextToSpeech

Prerequisites

Create an application

Install dependencies

Initialize your dependencies

Write the code

Add the following to VoiceController.cs:

Copy to Clipboard

var results = Client.Call.Do(new Call.CallCommand
{
    to = new[]
    {
        new Call.Endpoint {
            type = "phone",
            number = TO_NUMBER
        }
    },
    from = new Call.Endpoint
    {
        type = "phone",
        number = NEXMO_NUMBER
    },
    answer_url = new[]
    {
        "https://developer.nexmo.com/ncco/tts.json"
    }

View full source 

Run your code

Save this file to your machine and run it:

$ Run using your IDE

Prerequisites

Create an application

Install dependencies

Initialize your dependencies

Write the code

Add the following to index.php:

Copy to Clipboard
$call = $client->calls()->create([
    'to' => [[
        'type' => 'phone',
        'number' => TO_NUMBER
    ]],
    'from' => [
        'type' => 'phone',
        'number' => NEXMO_NUMBER
    ],
    'answer_url' => ['https://developer.nexmo.com/ncco/tts.json'],
]);

View full source 

Run your code

Save this file to your machine and run it:

$ php -t . -S localhost:3000

Prerequisites

Create an application

Install dependencies

Initialize your dependencies

Write the code

Add the following to make-an-outbound-call.py:

Copy to Clipboard
response = client.create_call({
  'to': [{'type': 'phone', 'number': TO_NUMBER}],
  'from': {'type': 'phone', 'number': NEXMO_NUMBER},
  'answer_url': ['https://developer.nexmo.com/ncco/tts.json']
})

pprint(response)

View full source 

Run your code

Save this file to your machine and run it:

$ python3 make-an-outbound-call.py

Prerequisites

Create an application

Install dependencies

Initialize your dependencies

Write the code

Add the following to outbound_tts_call.rb:

Copy to Clipboard
response = client.calls.create(
  to: [{
    type: 'phone',
    number: RECIPIENT_NUMBER
  }],
  from: {
    type: 'phone',
    number: NEXMO_NUMBER
  },
  answer_url: [
    'https://developer.nexmo.com/ncco/tts.json'
  ]
)

View full source 

Run your code

Save this file to your machine and run it:

$ ruby outbound_tts_call.rb

Try it out

When you run the code the TO_NUMBER will be called and a text-to-speech message will be heard if the call is answered.