Retrieve information for a call

A building block that shows how to retrieve information for a call. The call to retrieve information for is identified via a UUID.

Example

Replace the following variables in the example code:

Key Description
UUID The UUID for the call for which information is being requested.

Prerequisites

Use your existing application

To fetch information about a call, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the call.

Write the code

Add the following to retrieve-info-for-a-call.sh:

Copy to Clipboard
curl "https://api.nexmo.com/v1/calls/"$UUID \
  -H "Authorization: Bearer "$JWT \

View full source 

Run your code

Save this file to your machine and run it:

$ bash retrieve-info-for-a-call.sh

Prerequisites

Use your existing application

To fetch information about a call, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the call.

Install dependencies

$ npm install nexmo dotenv
Initialize your dependencies

Create a file named app.js and add the following code:

Copy to Clipboard
const Nexmo = require('nexmo');

const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET,
  applicationId: NEXMO_APPLICATION_ID,
  privateKey: NEXMO_PRIVATE_KEY
}, {debug: true});

View full source 

Write the code

Add the following to app.js:

Copy to Clipboard
nexmo.calls.get(CALL_UUID, (err, res) => {
  if(err) { console.error(err); }
  else {
      console.log(res);
  }
});

View full source 

Run your code

Save this file to your machine and run it:

$ node app.js

Prerequisites

Use your existing application

To fetch information about a call, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the call.

Install dependencies

Add the following to build.gradle:

compile 'com.nexmo:client:4.0.0'
Initialize your dependencies

Create a class named RetrieveCallInfo and add the following code to the main method:

Copy to Clipboard
NexmoClient client = new NexmoClient.Builder()
        .applicationId(NEXMO_APPLICATION_ID)
        .privateKeyPath(NEXMO_PRIVATE_KEY_PATH)
        .build();

View full source 

Write the code

Add the following to the main method of the RetrieveCallInfo class:

Copy to Clipboard
System.out.println(client.getVoiceClient().getCallDetails(UUID));

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 gradle command to execute your application, replacing com.nexmo.quickstart.voice with the package containing RetrieveCallInfo:

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

Prerequisites

Use your existing application

To fetch information about a call, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the call.

Install dependencies

$ Install-Package Nexmo.Csharp.Client
Initialize your dependencies

Create a file named VoiceController.cs and add the following code:

Copy to Clipboard
var client = new Client(creds: new Nexmo.Api.Request.Credentials
{
    ApiKey = "NEXMO_API_KEY",
    ApiSecret = "NEXMO_API_SECRET",
    ApplicationId = "NEXMO_APPLICATION_ID",
    ApplicationKey = "NEXMO_APPLICATION_PRIVATE_KEY"
});

View full source 

Write the code

Add the following to VoiceController.cs:

Copy to Clipboard
            var call = Client.Call.Get(NEXMO_CALL_UUID);
            ViewData.Add("call", call);

            return View();
        }

        [HttpPost]
        public ActionResult MuteCall(string id)
        {
            var NEXMO_CALL_UUID = Session["UUID"].ToString();

            var result = Client.Call.Edit(NEXMO_CALL_UUID, new Call.CallEditCommand
            {
                action = "mute"
            });

            return RedirectToAction("MakeCall");
        }

        [HttpPost]
        public ActionResult UnmuteCall(string id)
        {
            var NEXMO_CALL_UUID = Session["UUID"].ToString();

            var result = Client.Call.Edit(NEXMO_CALL_UUID, new Call.CallEditCommand
            {
                action = "unmute"
            });

            return RedirectToAction("MakeCall");
        }

        [HttpPost]
        public ActionResult EarmuffCall(string id)
        {
            var NEXMO_CALL_UUID = Session["UUID"].ToString();

            var result = Client.Call.Edit(NEXMO_CALL_UUID, new Call.CallEditCommand
            {
                action = "earmuff"
            });

            return RedirectToAction("MakeCall");
        }

        [HttpPost]
        public ActionResult UnearmuffCall(string id)
        {
            var NEXMO_CALL_UUID = Session["UUID"].ToString();

            var result = Client.Call.Edit(NEXMO_CALL_UUID, new Call.CallEditCommand
            {
                action = "unearmuff"
            });

            return RedirectToAction("MakeCall");
        }

        [HttpPost]
        public ActionResult HangupCall()
        {
            var NEXMO_CALL_UUID = Session["UUID"].ToString();

            var result = Client.Call.Edit(NEXMO_CALL_UUID, new Call.CallEditCommand
            {
                action = "hangup"
            });

            return RedirectToAction("MakeCall");
        }

        [HttpPost]
        public ActionResult PlayttsToCall()
        {
            var NEXMO_CALL_UUID = Session["UUID"].ToString();
            var TEXT = "This is a text to speech sample";

            var result = Client.Call.BeginTalk(NEXMO_CALL_UUID, new Call.TalkCommand
            {
                text = TEXT,
                voice_name = "Kimberly"
            });

            return RedirectToAction("MakeCall");
        }

        [HttpPost]
        public ActionResult PlayAudioStreamToCall()
        {
            var NEXMO_CALL_UUID = Session["UUID"].ToString();

            var result = Client.Call.BeginStream(NEXMO_CALL_UUID, new Call.StreamCommand
            {
                stream_url = new[]
                {
                    "https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3"
                }
            });

            return RedirectToAction("MakeCall");
        }

        [HttpPost]
        public ActionResult PlayDTMFToCall()
        {
            var NEXMO_CALL_UUID = Session["UUID"].ToString();
            var DIGITS = "1234";

            var result = Client.Call.SendDtmf(NEXMO_CALL_UUID, new Call.DtmfCommand
            {
                digits= DIGITS
            });

            return RedirectToAction("MakeCall");
        }
    }
}

View full source 

Run your code

Save this file to your machine and run it:

$ Run using your IDE

Prerequisites

Use your existing application

To fetch information about a call, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the call.

Install dependencies

$ composer require nexmo/client
Initialize your dependencies

Create a file named index.php and add the following code:

Copy to Clipboard
$keypair = new \Nexmo\Client\Credentials\Keypair(
    file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH),
    NEXMO_APPLICATION_ID
);

$client = new \Nexmo\Client($keypair);

View full source 

Write the code

Add the following to index.php:

Copy to Clipboard
$call = $client->calls()->get(NEXMO_CALL_UUID);
echo json_encode($call).PHP_EOL;

View full source 

Run your code

Save this file to your machine and run it:

$ php index.php

Prerequisites

Use your existing application

To fetch information about a call, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the call.

Install dependencies

$ pip install nexmo
Initialize your dependencies

Create a file named retrieve-info-for-a-call.py and add the following code:

Copy to Clipboard
import nexmo
from pprint import pprint

client = nexmo.Client(
    application_id=APPLICATION_ID,
    private_key=APPLICATION_PRIVATE_KEY_PATH,
)

View full source 

Write the code

Add the following to retrieve-info-for-a-call.py:

Copy to Clipboard
# Note call can be made to current call or a completed call
response = client.get_call("NEXMO_CALL_UUID")
pprint(response)

View full source 

Run your code

Save this file to your machine and run it:

$ python3 retrieve-info-for-a-call.py

Prerequisites

Use your existing application

To fetch information about a call, you must use the same NEXMO_APPLICATION_ID and private key that were used to create the call.

Install dependencies

$ gem install nexmo
Initialize your dependencies

Create a file named retrieve-info-for-a-call.rb and add the following code:

Copy to Clipboard
require 'nexmo'

client = Nexmo::Client.new(
    application_id: NEXMO_APPLICATION_ID,
    private_key: File.read(NEXMO_APPLICATION_PRIVATE_KEY_PATH)
)

View full source 

Write the code

Add the following to retrieve-info-for-a-call.rb:

Copy to Clipboard
response = client.calls.get(NEXMO_CALL_UUID)

puts response.inspect

View full source 

Run your code

Save this file to your machine and run it:

$ ruby retrieve-info-for-a-call.rb

Try it out

You will need to:

  1. Set up a call and obtain the call UUID. You could use the 'connect an inbound call' building block to do this.
  2. Retrieve information for the call (this building block).