3

I have been reading all the documentation and have yet to really find an answer to this question:

Is there any way to get the current wait time in a live agent chat queue? From what I was reading there is no way to get it with the default Live Agent enabled.

Based on Omni-Channel Developer’s Guide it appears the AgentWork table has the information I need as it has a field called: RequestDateTime. Which means if I use that and the current time of everyone in a Assigned status. I would be able to calculate the average wait time before someone is in chat.

Now when I query the table AgentWork I do not get any records even though a chat is currently in queue.

What records should show up in AgentWork? Is there a better way I can get the wait time of chats currently in the queue?

  • A chat which is currently in queue does not create any AgentWork record. Record is created once the Agent see request. – Ashwani May 6 '17 at 10:44
2

There is no way directly from Salesforce to give a wait time. You could implement a custom VisualForce page and use the liveAgent:clientChatQueuePosition component, along with historical data from your org to see what the average wait time for a chat is. So number of users ahead + average wait time per user = current wait time in queue. But there is no built in way from Salesforce to accomplish that.

2

So for completeness I'm going to answer my question. Agentwork only works if you are using OmniChannel for chat. LiveAgent chat will not populate Agentwork object.

Now one thing to call out there is a nasty bug currently in Salesforce that if the Chat is transferred to another agent. What happens is the RequestDateTime field is null Salesforce treats this as a 0 for a date/time field which they store as a Epoch. Which then gives you SpeedToAnswer of 47 years. As they calculate it the following way AcceptDatetime - RequestDateTime = SpeedToAnswer.

More information can be found here. So I added a condition in my where clause to throw away anything with a greater then 10000 seconds wait time (Which should never happen in my Company Anyway).

Public String generateWaitTimeMessage(string queueToQuery)
{
    Final Integer MINS_TO_QUERY = -60;
    DateTime currentTime = system.now();
    DateTime currentTimeOffset = currentTime.addMinutes(MINS_TO_QUERY);
    List<AgentWork> agentWorkList = [SELECT id, SpeedToAnswer, OriginalQueue.DeveloperName, createddate 
                                     FROM AgentWork
                                     WHERE OriginalQueue.DeveloperName = :queueToQuery
                                     AND createddate > :currentTimeOffset
                                     AND SpeedToAnswer != NULL
                                     AND SpeedToAnswer < 10000
                                     ORDER BY createddate desc
                                     LIMIT 10];

    Integer count = 0;
    Integer waitTimeTotal = 0;
    for(AgentWork aw : agentWorkList)
    {
        waitTimeTotal += aw.SpeedToAnswer;
        count++;
    }

    Integer avgWaitTime = 0;
    if( count > 0 )
    {
        avgWaitTime = waitTimeTotal/count;
    }
    Integer minutes = avgWaitTime / 60;
    Integer seconds = math.mod(avgWaitTime,60);

    String newTimeMessage = 'Chat is Currently Open';
    if(avgWaitTime > 30) 
    {
        String second = 'seconds';
        String minute = 'minutes';
        if(minutes == 1) minute = 'minute';
        if(seconds == 1) second = 'second';
        if(avgWaitTime >= 60)
        {
            newTimeMessage = 'An agent should be available in '+minutes+' '+minute+' and '+seconds+' '+second+'.';
        }
        else
        {
            newTimeMessage = 'An agent should be available in '+seconds+' '+second+'.';
        }
    }
    return newTimeMessage;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.