JSFiddle - React, Tailwind, and code Playground

by Kevin Glinski

HTML

<input id='callIdInput' value='1001600043'></input>
<button id='waitTimeButton'>Get Wait Time</button>

JavaScript

/**
BEFORE RUNNING: Change the User/Password/Server values

There is a handler toolstep that can give you this value, but outside the handler we have to calculat it ourselves.

From the Handler Documentation:

Wait time is calculated using the average wait time for the queue and subtracting the amount of time that the call
has been on the queue. Average wait time is calculated by adding the total wait time for all calls answered in a given period
(the previous 30 minutes) and dividing that total by the number of calls answered in that period.

((Previous Period Total Wait Time) / (Previous Period Total Calls)) - (Current Call Wait Time)

In ICWS, there is a stat for average wait time:
Average Wait Time
StatID: inin.workgroup:AverageWaitTime
Type:   statisticDurationValue
Parameters:
ININ.People.WorkgroupStats:Workgroup
ININ.Queue:Interval

Through a series of ICWS calls, we will connect to the server, find the workgroup for the call, get the workgroup statistics, then do the calculations for wait time and output the estimated wait time in an alert.

**/

var APPNAME = "EstimatedWaitTime";
var sessionId = null;
var csrfToken = null;
var userId = "kevin.glinski";
var password = "1234";
var server = "http://morbo.dev2000.com:8018/icws/";

function getWaitTime() {
    sessionId = null;
    csrfToken = null;

    var interactionId = document.getElementById('callIdInput').value;

    loginData = {
        "__type": "urn:inin.com:connection:icAuthConnectionRequestSettings",
            "applicationName": APPNAME,
            "userID": userId,
            "password": password
    };

    //Connect to the server
    sendRequest("POST", "connection", loginData, function (data) {
        sessionId = data.sessionId;
        csrfToken = data.csrfToken;

        //Get the Queue name and when the interaction entered the queue
        //Eic_WorkgroupQueueTimestamp,Eic_WorkgroupName
        sendRequest("GET", "/interactions/" + interactionId +...