Skip to content

Instantly share code, notes, and snippets.

@jarrodbell
Last active February 21, 2016 23:58
Show Gist options
  • Save jarrodbell/bee5f52b964aa13f19cc to your computer and use it in GitHub Desktop.
Save jarrodbell/bee5f52b964aa13f19cc to your computer and use it in GitHub Desktop.
Cisco Telepresence call history processing example
// Create an object that we can update as we get data in, before adding a complete entry to a list
var currentCallData = {};
CF.userMain = function() {
// The regex for this feedback item should be: CallHistoryRecentResults Entry (\d+)
CF.watch(CF.FeedbackMatchedEvent, "TELEPRESENCE", "HISTORY_CALL_FEEDBACK", function(fbName, data) {
// We get three rows of data for each actual call:
// CallHistoryRecentsResult Entry 0 CallbackNumber: "sip:555...@domain.com"
// CallHistoryRecentsResult Entry 0 DisplayName: "5557777"
// CallHistoryRecentsResult Entry 0 LastOccurrenceStartTime: "2016-02-03T17:00:42"
// Use regex to capture all the relavent parts of the data
var matches = data.match(/CallHistoryRecentsResult Entry (\d+) (\w+): "(.*?)"/);
// matches[0] = whole string that matched the regex, ie. same as "data" variable.
// matches[1] = entry ID
// matches[2] = data type (CallbackNumber, DisplayName, etc)
// matches[3] = data between quotes
// Check that the data was formatted as we expected, and that we got matched data from the regex
if (!matches || matches.length != 4) {
CF.log("invalid CallHistoryRecentsResult: " + data); // Print an error to the debug log
return; // invalid data, so return here to stop processing the data.
}
// Check what type of data was matched
switch (matches[2]) {
case "CallbackNumber":
currentCallData = {id: matches[1], CallbackNumber: matches[3]}; // Create the new object with data
break;
case "DisplayName":
currentCallData["DisplayName"] = matches[3];
break;
case "LastOccurrenceStartTime":
currentCallData["Time"] = matches[3];
// Finally, we can add the item to the top of the list (assuming time is the last piece of data needed for the entry)
CF.listAdd("l400", [{
"s260": currentCallData.DisplayName,
"s261": currentCallData.Time,
"s262": currentCallData.CallbackNumber,
"d260": {
tokens: {
"entryid": currentCallData.id
}
}
}], 0); // The third param here forces to add at index 0 (top of list)
break;
default:
// The data didnt match anything we were looking for
CF.log("Unknown CallHistoryRecentsResult Type: " + data); // Print an error to the debug log
break;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment