{uccx api: dynamically changing an agents skill}

Product: UCCX 9.x and above (the configuration API wasn’t available until 9.x)
Scenario: An Agents answers calls for CSQ A from 12PM – 6PM and then needs to answer calls for CSQ B from 6:30PM – 8PM.
Problem: In UCCX, the only way for an Agent to be a member of more than one CSQ is to use Skills. In the Post, I will use a very simple demonstration of a Use of the API to Automate the Changing of an Agents Skill in order for that Agent to answer calls from different CSQs (and not overlap).
Disclaimer: This Post assumes you have Node.js installed and the Request Library loaded as a dependency in your project. I’m not going to show you how to install Node and or Request. The code I will leave you is classified as a Minimum Viable Product; for example, it seems as though the NodeJS rendition of the setTime function could cause memory leaks. Use this code at your own risk..Ultimately I wanted to demonstrate the use of the API in a real-world scenario as mentioned here.

I could use many tools to perform this little magic trick..Python, Java, Ruby, etc; today I wanted to break out Node.JS mainly to show you CRUD operations in a different language..and Node is just cool too!

Let’s break down this problem into it’s simplest form:

First this script needs to be executed before 6:30pm.

The Script starts by getting the difference btw script
execution and the first Agent Skill Change 6:30pm (1830). This
intervalTime is used in a JS setTimeout function that fires
a function when the Interval is reached (@1830). 

At that point, the Agent Skill gets changed and
another Interval Time is set for 8pm (2000).

When the 8pm interval is triggered, the Agent skill changes
to the initial skill again and the Datetime is reset for the
following day at 6:30pm.

The first problem I had to tackle (using javascript) was Time. As I mentioned this script needs to execute before 6:30pm when the Agent’s Skill needs to change.

module.exports.getInterval = function(iter) {
 var date = new Date();
 switch (iter) {
  case 1:
   var changeSkill =
    new Date(date.getFullYear(), date.getMonth(), date.getDate(), 18, 30, 00);
  case 2:
   var changeSkill =
    new Date(date.getFullYear(), date.getMonth(), date.getDate(), 20, 00, 00);
  case 3:
   var tomDate = new Date(date);
   //Add One Day to Today's Date to get Tomorrow
   tomDate.setDate(date.getDate() + 1);
   var changeSkill =
    new Date(tomDate.getFullYear(), tomDate.getMonth(), tomDate.getDate(), 18, 30, 00);
  return changeSkill.getTime() - date.getTime();

Suffice it to say, the first iteration (case 1) will only ever run once (during the initial execution of the script). In the 3rd interval, the Skill is changed and the clock is reset to change the Skill Again..for the following day @ 1830 (6:30pm). And the return is in milliseconds: setTimeout(callback, millisec)

This script is set to run indefinitely (on whatever computer/server you deem viable: Node runs on Windows, OS X, and many flavors of Linux distros); it is able to run indefinitely by using setTimeout which calls a function that executes our script logic..resets our interval and then calls the setTimeout again in a recursive manner..this is actually a pretty common scenario.

function callback() {
  if (skill is this) {
    //do stuff including setting new interval
    setTimeout(callback, interval);
  } else {
    //do other stuff including setting new interval
    setTimeout(callback, interval);
setTimeout(callback, interval);

Next up, is the API Call using CRUD: In this post Retrieve and Update (GET, PUT). First we have to Create an Object (JSON) which are the Options we will use to make our Request..below is what is looks like..it should actually be pretty self-explanatory unless you are new to this..

var options = {
  uri : uri,
  method : 'GET/POST/PUT/DELETE',
  auth : {
    user : username,
    pass : password
  header : {
    'Content-Type' : 'application/json',
    'Accept' : 'application/json'
  strictSSL : false,
  json : jsonObj

Next up is using Request which, once the Options Object has been put together properly is pretty “easy”.

var request = require('request');
request(options, function(error, response, body) {
  // Body will be our JSON data we want to PARSE
  var json = JSON.parse(body);
  //If there was an Error we will get a JSON object returned
  // We can collect our response (codes) in the case of
  // Updating data where JSON is not returned (201, 204, etc etc)

Ok things you will need to do/change in my script to get this off the ground:

// Change the IP Address in the Options
// Change User/Password
// Change The Skill Name to Match Yours (skill_a, skill_b)
// Change The Agent Name to Match Yours (resource/agent1)
// I use 2 Files for this..Keep them together in the same Directory...
// If you know NODE you'll know how to use this..
// To Execute the Example from the Command Line
$node timeEvent_example.js

And the CODE:

return sam;

2 responses to “{uccx api: dynamically changing an agents skill}

  1. accedeholdingsptyltd

    I hope your code works on my ongoing project.

  2. Great stuff, will be trying this out

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s