Sample Applications and their source codes are available on Github to enable developers to understand how to build applications using EnableX API. Each of the sample application is developed to showcase a specific use case. Therefore, these applications methods may not cover every aspect of EnableX API, but helps you get started with coding quickly.

Happy Coding!

All Voice service APIs are REST implementation, so unlike other services these do not have any language or framework binding. Developer just needs to figure out on how to make these REST request and also respond to WebHooks and or REST events/responses from the EnableX server.
As a showcase, all samples on the github are developed using nodejs.

All these samples assume that you have an active account on EnableX platform and valid App_ID and App_Key

How to get account

Samples on the Github

The following section explains the implementation of the applications based on voice service APIs. These examples show/suggest a way to implement functionalities, developers are free to integrate the APIs. The code is organized as follows:.

  • This file contains all the wrappers to make REST calls using nodejs. The main wrapper function is written as makeVoiceAPICall, gathers all the parameters into the JSON object, and sends the appropriate request (POST/GET/PUT/DELETE) on the REST request. The implementation of makeVoiceAPICall is shown below:
var makeVoiceAPICall = function(voice_path, method, postData, auth_header, auth_token, callback){
     var voiceHost = "voice.enablex.com" , voicePort = 443;
     let headers = {
         'Authorization': 'Basic ' + new Buffer(app_id + ':' + app_key).toString('base64'),
         'Content-Type': 'application/json',
     };
if(auth_header !== undefined)
    headers['x-vcloudx-digest'] = auth_header;

if(auth_token !== undefined)
    headers['x-vcloudx-token'] = auth_token;

let options = {
    host: voiceHost,
    port: voicePort,
    path: voice_path,
    method: method,
    headers: headers
};

if(postData !== undefined)
    options.headers['Content-Length'] = postData.length;
    req = http.request(options, function(res) {
    var body = "";
    res.on('data', function(data) {
        body += data;
    });
    res.on('end', function() {
        callback(body);
    });
    res.on('error', function(e) {
        console.error("Got error: " + e.message);
    });
});
if(postData !== undefined)
    req.write(postData);
req.end();
};
  • config.js — Contains all the parameters that would be passed as data to various json object. JSON objects contain directives for voice APIs.
  • Please note that this config is application-specific and used as a convenience for writing sample applications. This data can be passed within the developed program in whichever way you store/fetch data.
config.voice_server_addr = '';// Your server address to reah from EnableX 
config.voice_server_port = XXXx;
config.app_id = 'app_id'; // App_Id from your account
config.app_key = 'app_key'; // App_Key from your account
config.webhook_port = 3000;
exports.playprompts = function(voice_id, callback) {

    let playtext = {voice_id:voice_id, text:config.text, language:'en-IN',voice:'female', prompt_ref:'welcome-prompt'};

    enxVoice.playprompts(playtext, function(ret, response) {
    let msg = JSON.parse(response);
    if(ret === false || msg.status === "failed") {
        console.error("["+voice_id+"] Failed to play voice menu");
        callback(false);
        return;
    }
    callback(true);
    });
}

Setting up the sample application

Installation

$git clone https://github.com/EnableX/Sample-Voice-Client-with-EnableX-\
Voice-APIs.git
$cd git_directory 
$npm install

Starting the application

$ node application_name 

List of Github Samples

Accept Incoming Call and play voice menu

Target:

In this sample, we shall create a small program that will accept the incoming call, play the welcome greeting, and an IVR. The program will detect DTMFs pressed by the caller and will display the DTMFs on the console

Pre-requisite
  1. Phone number — For accepting an incoming call, you need to buy a dedicated phone number. Please check HowTo buy a phone number
  2. Upload a “Welcome Greeting” on to the portal, that needs to be played when a call is connected. Please check HowTo upload the audio prompt.
  3. Configure a webhook for accepting incoming call notification

Program / Algorithm

  • When an incoming call lands on the platform and if the incoming call greeting is configured, the call gets accepted automatically by the platform.
  • The system plays the configured greeting on the incoming call and then triggers the configured webhook.
  • The developer needs to implement a webhook handler in the application server to respond to the webhook. Webhook sends a voice_id to uniquely identify the call for future processing.
    • As done in the sample program here:
var voiceeventhandler = function(voiceevent) {
   if(voiceevent.state !== undefined) {
     if(voiceevent.state === 'incomingcall') {
       voice_id = voiceevent.voice_id;
       console.log("["+voice_id+"] Received incoming call from " + voiceevent.from);
     } if (voiceevent.state == 'disconnected') {
       console.log ("["+voice_id+"] call disconnected");
       shutdown();
     }
   }
  • Once you have voice_id from the webhook, we can use any voice API on this call. In this example you can play voice menu
code for playing voice menu can be found here:
https://github.com/EnableX/Sample-Voice-Client-with-EnableX-Voice-APIs/blob/master/incoming_playvoicemenu.js

Make an outgoing call and play text prompt once connected

Target:

In this sample, we will create a small program that will make an outbound call. Let the call get connected. Once call is connected use the Playprompt with the text.

Pre-requisite:

  1. Phone number — As a CLI, i.e. call line Identifier. You can use a shared number or dedicated depending on your use case. Please check HowTo buy a phone number

Program / Algorithm

  • Its a simple REST API to make an outbound call. You can play the chosen text as a part of the API in on_connect part of the JSON structure
  • The system plays the configured greeting on the incoming call and then triggers the configured webhook.
  • voiceeventhandler function implements events such as connectstate, playstate returned from the server. You can find more on these events from API documentation
code for playing voice menu can be found here:
https://github.com/EnableX/Sample-Voice-Client-with-EnableX-Voice-APIs/blob/master/outgoing_playtext.js

Accept the incoming call and forward it to another number

Target:

In this sample, we shall create a small program that will accept an incoming call. Let the call get connected. Once the call is connected use the Playprompt The program will respond to a webhook called configured for this incoming service. and call an outbound number through the API call.

Pre-requisite:

  1. Phone number — For accepting an incoming call, you need to buy a dedicated phone number. Please check HowTo buy a phone number
  2. Phone number for the outbound call — As a CLI, i.e. call line Identifier. You can use a shared number or dedicated depending on your use case.
  3. Upload a “Welcome Greeting” on to the portal, that needs to be played when a call is connected. Please check HowTo upload the audio prompt.
  4. Configure a webhook for accepting incoming call notification
  5. API for Outbound call

Program / Algorithm

  • Write a webhook for, Accept the incoming call.
  • If you just want to forward it, without accepting and without playing prompt file, please do not configure prompt for the incoming number
  • In webhook implementation, make a REST call for making an outbound call with specified CLI
  • voiceeventhandler function implements events such as connectstate, playstate returned from the server. You can find more on these events from API documentation
  • Program uses utils.forwardcall(voice_id, function(ret)) to form a bridge
code for playing voice menu can be found here:
https://github.com/EnableX/Sample-Voice-Client-with-EnableX-Voice-APIs/blob/master/incoming_bridge.js

Use Message Broadcast API and play text prompt on all calls

Target

In this sample, we shall create a small program that will accept list of calling numbers, call every number in the list and play the text prompt

Pre-requisite:

  1. List of numbers — List of numbers from your data source.
  2. Phone number for the outbound call — As a CLI, i.e. call line Identifier. You can use a shared number or dedicated depending on your use case.
  3. Text prompt to be played for every call.
  4. Configure a webhook for accepting the incoming notification

Program / Algorithm:

  1. Stringify the phone numbers that you want to dial
  2. Take a look at makeBroadCastAPICall function defined in clientbroadcast.js
  3. Add all the parameters as defined in the API documentation and pass the stringified data of the dialed numbers.
  4. Add prompts to be played
  5. If you want to take actions on selected individual calls, pass the webhooks to the broadcast callbacks
code for Making multiple calls and playing voice promp can be found here:
http://bitbucket.vcloudx.com/bitbucket/projects/VOIC/repos/voicemessaging/browse/examples/broadcast_playprompt.js