Tropo is part of CiscoLearn More

A Simple Call Center sample application

Posted on May 10, 2016 by Tim Scheuering

The challenge of building a basic call center application using Tropo might seem a bit overwhelming, so over the next few weeks, we’ll build one from a basic starting point we have here, to something that will demonstrate how a small business can use Tropo to answer, queue, and route their calls.

In this first part, we’ll have an inbound call from a customer that triggers an outbound call to an agent and places them both in the same conference. We’ve received many requests for a tutorial on how to record all conference participants, so this guide includes a simple recording function as well.

Why a conference instead of a transfer? A conference will let us do some interesting things later on, like adding a listen only mode for a supervisor or splitting the agent and caller legs to let them act separately.

Here’s the major components of this application (and provided info to help familiarize yourself with RESTful events) to try and make it simpler.

First, let’s create an overview of what we need:

  • A call director, to separate logic based on session type
  • An agent function, to handle agent joins/parts
  • An inbound caller function, to handle the initial call

Because JavaScript has no built in HTTP client, we’ll use a snippet from the knowledge base to simplify the REST calls:

function httpGet(url){ //Performs GET requests here 
	connection = new;
	connection.setRequestProperty("Content-Type", "text/plain");
	connection.setRequestProperty("charset", "utf-8");

	dis = new;
	while (dis.available() !== 0) {
		line = dis.readLine();

This will be the platform for all REST GET requests used in our application.

Because we need to record audio and launch user applications, we want to set some variables early on:

//Predefined Variables

var token = "MYTOKEN";
var launchURL = "";
var ftpAddress = ""
var ftpUserName = "USERNAME";
var ftpPassword = "PASSWORD";
var queueNumber = "+13215556677";

You need to change the values above to match those specific to your applications.

Next, we need to set up the basic call director structure:

var incoming = false; //Variable Constructor

if(currentCall){ //If the call is inbound, set incoming to true
 incoming = true;

if (incoming) {
	InboundLeg(currentCall.sessionId + "", token, launchURL, ftpAddress, ftpUserName, ftpPassword, queueNumber);
} else if (theCall == "agent") {
	call("+" + theAgentNumber);
	AgentLeg(currentCall.sessionId, theConfID, ftpAddress, ftpUserName, ftpPassword);
} else {
	log("xxxxxxxxxxLOGxxxxxxxxxx - ERROR: NO DIRECTION");

Notice in the above code, variables like theAgentNumber and theCall are passed parameters. More on parameters can be found in our Quickstart Documentation:

Now that we configured which direction the call is going before any real logic is performed, let’s generate the logic for each leg:

function InboundLeg(mySessionID, myToken, myLaunchURL, myFTP, myUN, myPW, myNumber) { //For Inbound Portion of Call
	startCallRecording("ftp://" + myUN + ":" + myPW + "@" + myFTP + "INBOUND-" + mySessionID + ".wav");

	say("Thank you for contacting the Call Center Template application.");

	say("We are connecting you to an agent now.");

	httpGet(myLaunchURL + myToken + "&theConfID=" + mySessionID + "&theCall=agent&theAgentNumber=" + myNumber);


function AgentLeg(mySessionID, myConfID, myFTP, myUN, myPW) { //For Agent Portion of Call
	log("xxxxxxxxxxLOGxxxxxxxxxx - " + mySessionID);
	startCallRecording("ftp://" + myUN + ":" + myPW + "@" + myFTP + "INBOUND-" + myConfID + "-AGENT-" + mySessionID + ".wav");

	say("Connecting you to a caller now");


You may notice the passed arguments to the AgentLeg function contain both the original caller’s sessionID (called myConfID at this point), as well as its own sessionId, to distinguish all interactions with the user from others.

At this point, the basic application is complete. A user calls in and is directed to an inbound leg. This leg then relaunches your application with agent leg details in place using the HTTP GET request with your application’s launch token. The agent leg then calls into the queue’s main number first, but can be changed to call into any number via a REST launch parameter. This allows you to transfer or connect new agents to the current inbound caller at will.

The complete, functioning code is available on Github.

Leave a Reply