setTimeout
The vcc.setTimeout() function is used within the VCC Live Contact Center Script module to execute a specified piece of code or function after a defined delay. Unlike the standard browser window.setTimeout(), which returns a numeric ID, vcc.setTimeout() returns a specialized timeout object. This object includes a .clear() method that can be used to cancel the scheduled execution.
Description
let timeoutObj = vcc.setTimeout(callbackFunction, delayInMilliseconds);
It allows users to execute callbacks after a period expressed in milliseconds.
Note: This function works similarly to the setTimeout() function in JavaScript; you can read about it here.
Parameters
function: function
The reference to the callback function
delay: integer
The time, in milliseconds, the timer should wait before executing the callback function..
Return values
None
Use cases with explanation
Use case 1. Creating a Recurring Interval (Polling / Looping)
Because the VCC environment might not fully support standard setInterval securely in all script modules, vcc.setTimeout() is frequently used recursively. By calling vcc.setTimeout() inside its own callback, you can capture inputs (like DTMF) or poll a status repeatedly until a condition is met.
// Example: Polling for exactly 4 DTMF digits every 1 second
let checkInterval;
function startFormatCheck() {
// Clear any existing loop before starting a new one
if (checkInterval) {
checkInterval.clear();
}
checkDigitsLoop();
}
function checkDigitsLoop() {
let dtmf = vcc.getScriptVariable("global.dtmf");
if (dtmf.length === 4) {
// We have our 4 digits, stop looping and enable submit
vcc.getController("payment_form", "btn_submit").disabled = false;
} else if (dtmf.length > 4) {
// Too many digits, clear DTMF and keep polling
vcc.clearDtmf();
checkInterval = vcc.setTimeout(checkDigitsLoop, 1000);
} else {
// Keep waiting by scheduling the next check
checkInterval = vcc.setTimeout(checkDigitsLoop, 1000);
}
}
Use case 2. Auto-Closing or Clearing Temporary Messages
Often, you want to show a success or error message to the agent and have it automatically vanish after a few seconds without requiring the agent to click anything.
// Example: Showing a temporary success message to the agent
function showTemporaryStatus(messageText) {
// Display the message
vcc.setFieldValue("status_alert", messageText);
vcc.getController("main_page", "status_alert").refresh();
// Clear the message after 3 seconds (3000 ms)
vcc.setTimeout(function() {
vcc.setFieldValue("status_alert", "");
vcc.getController("main_page", "status_alert").refresh();
}, 3000);
}
Use case 3. Delays Before Automatic Call Transfers
If a customer makes a choice that requires transferring the call (e.g., to a specific payment or language queue), it is good practice to play a prompt, wait a few seconds, and then execute the transfer.
// Example: Delaying a transfer to give the caller time to hear an automated warning
$("menu_page", "btn_transfer_billing").afterSetData = function() {
let transferTimeout;
// Update UI to let agent know transfer is pending
vcc.setFieldValue("transfer_status", "Transferring to bilingual billing agent in 3 seconds...");
vcc.getController("menu_page", "transfer_status").refresh();
// Delay the actual transfer invocation by 3000ms
transferTimeout = vcc.setTimeout(function() {
vcc.transfer("6543", true); // Transfer to queue 6543
}, 3000);
// Optionally, if the agent clicks "Cancel Transfer" before 3 seconds, call transferTimeout.clear()
};
Notes
- Clearing Timeouts: Always track the returned object if there is a possibility that the timeout needs to be canceled. For instance, if the call drops or the agent navigates away, you should use
.clear()to avoid null pointer exceptions or unintended script executions. - Reference Management: When passing the callback to
vcc.setTimeout(), ensure that variables used inside the callback are appropriately scoped. Since it executes later, closures will capture the state of variables as they exist when the callback runs.
vcc.setTimeout(function () {
dump('test');
}, 1000);
Comments
Can’t find what you need? Use the comment section below to connect with others, get answers from our experts, or share your ideas with us.
There are no comments yet.