lehelg | 2017-04-12 13:55:40 UTC | #1
I am trying to find the longest waiting time for a queue. Unfortunately, this is not one of the metrics that is returned by api/v2/analytics/queues/observations/query.
I can query /api/v2/routing/queues/{queueId}/conversations/calls and loop through every call that is returned, and for each call, loop through the participants, and if the "purpose" is "acd" and "state" is "connected", then assume that the call is still waiting in queue. For the wait time, I can calculate now() - participant.connectedTime, and then simply find the largest value.
Will this work? Is this the best way to retrieve this data or is there a better way?
--Lehel
tim.smith | 2017-04-12 20:17:17 UTC | #2
There isn't currently any statistic or query that will give you this information directly. You will have to query for conversations and then iterate over them to find the longest waiting conversation. PURE-975 exists to add a new longest waiting statistic.
lehelg | 2017-04-12 20:37:33 UTC | #3
tim.smith, post:2, topic:1175
PURE-975
Thanks Tim. Any idea on when PURE-975 will be released?
--Lehel
tim.smith | 2017-04-12 20:38:19 UTC | #4
It's not currently scheduled, but I associated this request with it for visibility.
lehelg | 2017-05-25 15:55:59 UTC | #5
I am trying to use the Longest Wait Time statistic in a wallboard application. I am retrieving the calls from /api/v2/routing/queues/{queueId}/conversations/calls. Then I figure out if they are on hold, and if so, for how long. This seems to work OK, but the data is delayed by up to 30 seconds. This creates a problem when displayed next to the real-time stats. The workgroup will say 0 calls waiting, yet longest wait time is 6 minutes. Is this delay expected? The UI is able to display the correct wait time for the calls. I can post my code if it would help.
--Lehel
lehelg | 2017-05-31 12:24:12 UTC | #6
@tim.smith Do you by chance have any ideas?
Here is my code:
var purecloud = require('purecloudapisdk_javascript'); var pureCloudSession = require('./../purecloud.js'); var _ = require('underscore'); var config = require('./../config.js'); var queueIDs = config.queueMappings.default; var co = require('co');
exports.interval = 1000; exports.promise = function(fulfill, reject) { console.log("Running Longest Wait Time Job"); console.log(new Date().toISOString());
co(function *(){ var queryResults = new Array(queueIDs.length); var promisesToResolve = new Array(queueIDs.length); var queueCalls = {}; var page = 1; var longestWait1 = 0;
// Get first page of calls for all queues for (i=0; i<queueIDs.length; i++) { queryResults[i] = getCallsForQueue(queueIDs[i], page); promisesToResolve.push(queryResults[i]); queueCalls[queueIDs[i]] = []; }; var res = yield promisesToResolve; promisesToResolve = [];
//loop through all the results to see if there are additional calls to retrieve for (i=0; i<queueIDs.length; i++) { queueCalls[queueIDs[i]] = queryResults[i].result.entities; page = 1; while (page < queryResults[i].result.pageNumber) { page++; queryResults[i] = getCallsForQueue(queueIDs[i], page); queueCalls[queueIDs[i]].push(queryResults[i]._result.entities); promisesToResolve.push(queryResults[i]); } }; res = yield promisesToResolve;
for (i=0; i<queueIDs.length; i++) { var longestWaitInQueue = getLongestWaitTime(queueCalls[queueIDs[i]]); console.log(queueIDs[i]); console.log("Longest call waiting"); console.log(longestWaitInQueue); longestWait1 = (longestWaitInQueue != '-' && longestWaitInQueue > longestWait1) ? longestWaitInQueue : longestWait1; }; if (longestWait1 == 0) { longestWait1 = '-'; } else { var minutes = Math.floor(longestWait1 / 60), seconds = Math.round(longestWait1 - (minutes * 60)); longestWait1 = minutes + ":" + (seconds < 10 ? '0' + seconds : seconds); }
var response = { longestWait1: {text: longestWait1} };
console.log(response); fulfill(response); console.log("response sent"); console.log(new Date().toISOString()); // => [1, 2, 3] }).catch(function(error){ console.log("Error"); console.log(error); reject(error); }); };
function getCallsForQueue(queueID, pageNumber) { console.log("Getting calls for " + queueID); var requestPath = '/api/v2/routing/queues/' + queueID + '/conversations/calls'; var requestQuery = {}; var requestBody;
requestQuery["pageSize"] = '100'; requestQuery["pageNumber"] = pageNumber;
return pureCloudSession.makeRequest('GET', requestPath, requestQuery, requestBody); };
function getLongestWaitTime(result) { console.log("Finding the longest wait Time"); console.log(result); var maxWaitTime = "0"; //If there are calls, then true if (result.length > 0) { result.forEach (function (call){ call.participants.forEach (function (participant){ console.log(participant); if (participant.purpose == 'acd' & participant.state == 'connected') { console.log("Call is waiting on hold"); var holdtime = (new Date().getTime() - new Date(participant.connectedTime).getTime()) / 1000; //Divide by 1000 to convert to seconds console.log(holdtime); maxWaitTime = holdtime > maxWaitTime ? holdtime : maxWaitTime; }; }); }); }; if (maxWaitTime == "0") { return "-"; } else { return maxWaitTime; }; };
tim.smith | 2017-05-31 13:53:01 UTC | #7
The resource /api/v2/routing/queues/{queueId}/conversations/calls was removed for several reasons. The correct way to get calls in a queue is to use an analytics query. I tested using the body below and was able to see the call in queue immediately after it entered queue (at the same time the UI stats updated).
POST /api/v2/analytics/conversations/details/query
{
"interval": "2017-05-31T06:00:00.000Z/2017-06-01T06:00:00.000Z",
"order": "asc",
"orderBy": "conversationStart",
"paging": {
"pageSize": 25,
"pageNumber": 1
},
"segmentFilters": [
{
"type": "or",
"predicates": [
{
"type": "dimension",
"dimension": "queueId",
"operator": "matches",
"value": "636f60d4-04d9-4715-9350-7125b9b553db"
}
]
}
],
"conversationFilters": [
{
"type": "or",
"predicates": [
{
"type": "dimension",
"dimension": "conversationEnd",
"operator": "notExists",
"value": null
}
]
}
]
}
tim.smith | 2017-05-31 13:54:55 UTC | #8
You could also use the v2.routing.queues.{id}.conversations notification topic to get queue conversation events in real time so you don't have to poll.
Daniel_Grosso | 2017-08-09 09:23:49 UTC | #9
Hello Tim.
We are interested in this metric too. If we understood correctly, this query give us a list of conversations, for a given queue, in a given period of time. It filters conversations that started but did not ended. This will include both waiting time and agent time, right? would it be possible to differentiate them? If so, it would gives the ability to get "the longest waiting call" and also "the longest agent interaction call".
Thanks in advance.
Regards, Daniel
system | 2017-08-28 19:33:49 UTC | #10
This post was migrated from the old Developer Forum.
ref: 1175