CCC Example

Call Center Connect Example

This example will show how to login an agent and receive calls using the Hosted Call Center API.

Quick Links

Example Java Code

public class HostedCallCenterExample 
{
	public static void main(String [] args)
	{
		// First fill in all the valid information for your API Campaign
		String apiKey = "<REPLACE WITH YOUR API KEY>";
		long campaignId = "<REPLACE WITH YOUR CAMPAIGNID>";
		// Put in the Agent's Phone Number, they will be taking all the calls
		String agentPhoneNumber = "<ADD YOUR PHONE NUMBER>"; 
		// This is a userid for the agent - add something for your tracking purposes
		String agentUserid = "<CREATE A USERID TO TRACK YOURSELF>"; 
		
		HostedCallCenterExample hcc = new HostedCallCenterExample(apiKey);
		
		// Start the Hosted Call Center Example with logging into a campaign
		// 1) First send a call to the agent and have them listen to the agent id
		hcc.agentCallback(campaignId, agentPhoneNumber, agentUserid);
		
		// 2) Collect their agentid and login the agent into the system
		String agentId = HostedCallCenterExample.readInput("Type in the Agent ID that you hear on the phone");
		hcc.agentLogin(agentId);
		
		// 3) Now wait till a call is connected
		CallType firstConnection = hcc.getAgentConnection();
		
		// 4) When call is connected, display info to the user and remind them not to hang up their call
		// 5) Take in some response from them and when they are done they will press enter for the next call
		System.out.println("First Connection made to : " + firstConnection.getPhonenumber().getValue());
		String firstResponse = HostedCallCenterExample.readInput("Don't hangup, just type in your phone response and hit enter when youre done");
		
		// 6) Now lets store the response and get the user another call
		hcc.storeAgentResponse_sendNewCall(firstConnection.getCallid().toString(), firstResponse, "No Notes");
		
		// 7) Wait till second call is connected, display info to the user. 
		//    For this example this will be their last call and we will tell them to hang up after we collect their response.
		CallType secondConnection = hcc.getAgentConnection();
		System.out.println("Second Connection made to : " + secondConnection.getPhonenumber().getValue());
		String secondResponse = HostedCallCenterExample.readInput("Type in your response and hit enter when youre done");

		// 8) Now lets store the response and we won't send any new calls. Notify user to hangup their phone afterwards
		hcc.storeAgentResponse_NoNewCalls(secondConnection.getCallid().toString(), firstResponse, "No Notes");
		System.out.println("Thank You. Please hang up your phone now.");
	}
	
	private String apikey;
	private long campaignId;
	private String agentUserId;
	private String agentId;
	
	PredictiveService service;
	PredictiveServicePortType connection;

	/**
	 * Construct the connection to the API using the auto generated jax-ws code
	 * @param apikey the API key for CallFire.com
	 */
	public HostedCallCenterExample(String apikey)
	{
		this.apikey = apikey;
		service = new PredictiveService();
		connection = service.getPredictiveServiceHttpPort();
	}
	
	/**
	 * This is the first step of login. The agent must get a phone call which they don't hangup for the entire session
	 * @param campaignId The campaign id to be logged into
	 * @param agentPhoneNumber The phone number of the agent
	 * @param agentUserId A userid used by us to track the agent - Usually Agents firstname
	 */
	public void agentCallback(long campaignId, String agentPhoneNumber, String agentUserId)
	{
		this.campaignId = campaignId;
		this.agentUserId = agentUserId;
		connection.sendAgentCallBack(apikey, campaignId, agentUserId, agentPhoneNumber);
	}
	
	/**
	 * This is the second step of login. This is the Agent ID that the AGent hears on the phone when they pickup. CallFire
	 * will use this Agent ID to associate the phone call with the API session.
	 * @param agentId The agent id that is heard on the phone
	 */
	public void agentLogin(String agentId)
	{
		this.agentId = agentId;
		connection.loginAgent(apikey, campaignId, agentId, agentUserId);
	}
	
	/**
	 * Get the connection that the Agent is on. Call this after login and after each stored response
	 * so you can quickly popup information about the connected call.
	 * 
	 * @return CallType object that contains all the information about the connected call
	 */
	public CallType getAgentConnection()
	{
		return connection.getConnectionForAgent(apikey, campaignId, agentId);
	}
	
	/**
	 * This signals the end of a call and a request for the next call. Provide any responses and notes for
	 * that callfire can store for that call.
	 * 
	 * @param callId The call that is being finished
	 * @param response Any response left by the agent
	 * @param additionalNotes Any notes left by the agent
	 */
	public void storeAgentResponse_sendNewCall(String callId, String response, String additionalNotes)
	{
		connection.storeAgentResponse(apikey, campaignId, agentId, callId, response, additionalNotes, false);
	}
	
	/**
	 * This signals the end of a call but NO New calls. Provide any responses and notes for
	 * that callfire can store for that call.
	 * 
	 * Request that the Agent hangup their phone after this function is complete.
	 * 
	 * @param callId The call that is being finished
	 * @param response Any response left by the agent
	 * @param additionalNotes Any notes left by the agent
	 */
	public void storeAgentResponse_NoNewCalls(String callId, String response, String additionalNotes)
	{
		connection.storeAgentResponse(apikey, campaignId, agentId, callId, response, additionalNotes, true);
	}
	
	/**
	 * Generic Standard input reader
	 * 
	 * @param requestString Info to output to the user about their input.
	 * @return What the user typed
	 */
	public static String readInput(String requestString)
	{
		try
		{
		//  open up standard input
		    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		    System.out.print(requestString + ": ");
	        String str = br.readLine();
	
	        return str;
		}
		catch(Exception e)
		{
			return "";
		}
	}
}