Creates a new Task instance which provides the following features:
The routing contact service instance
The web calling service instance
Initial task data
Wrap-up configuration data
Optional
autoAuto-wrapup timer for the task This is used to automatically wrap up tasks after a specified duration as defined in AutoWrapup
Event data received in the Contact Center events. Contains detailed task information including interaction details, media resources, and participant data as defined in TaskData
Map associating tasks with their corresponding call identifiers.
Private
contactPrivate
localPrivate
metricsPrivate
webPrivate
wrapupAgent accepts the incoming task. After accepting, the task will emit task:assigned event and for voice calls, a task:media event with the audio stream.
Promise
Error if accepting task fails or media requirements not met
// Set up event handlers before accepting
task.on(TASK_EVENTS.TASK_ASSIGNED, () => {
console.log('Task assigned, ID:', task.data.interactionId);
// Update UI to show active task
});
// For voice calls, handle media
task.on(TASK_EVENTS.TASK_MEDIA, (track) => {
const audioElement = document.getElementById('remote-audio');
audioElement.srcObject = new MediaStream([track]);
});
// Accept the task
try {
await task.accept();
console.log('Successfully accepted task');
} catch (error) {
console.error('Failed to accept task:', error);
// Handle error (e.g., show error message to agent)
}
Consults another agent or queue on an ongoing task for further assistance. During consultation, the original customer is typically placed on hold while the agent seeks guidance from another agent or queue.
Configuration for the consultation containing:
Promise
Error if consultation fails or invalid parameters provided
// Consult with another agent
const consultPayload = {
to: 'agentId123',
destinationType: DESTINATION_TYPE.AGENT,
holdParticipants: true
};
task.consult(consultPayload)
.then(response => console.log('Consultation started successfully'))
.catch(error => console.error('Failed to start consultation:', error));
// Consult with a queue
const queueConsultPayload = {
to: 'salesQueue123',
destinationType: DESTINATION_TYPE.QUEUE
};
task.consult(queueConsultPayload)
.then(response => console.log('Queue consultation started'))
.catch(error => console.error('Failed to start queue consultation:', error));
Transfer the task to the party that was consulted. This completes a consultative transfer where the agent first consulted with the target before transferring the task. For queue consultations, the transfer is automatically directed to the agent who accepted the consultation.
Configuration for the consultation transfer containing:
Promise
Error if transfer fails, no agent has accepted a queue consultation, or other validation errors
// Complete consultation transfer to an agent
const agentConsultTransfer = {
to: 'agentId123',
destinationType: CONSULT_TRANSFER_DESTINATION_TYPE.AGENT
};
task.consultTransfer(agentConsultTransfer)
.then(response => console.log('Consultation transfer to agent completed'))
.catch(error => console.error('Failed to complete agent consultation transfer:', error));
// Complete consultation transfer to a queue agent
const queueConsultTransfer = {
to: 'queue123',
destinationType: CONSULT_TRANSFER_DESTINATION_TYPE.QUEUE
};
task.consultTransfer(queueConsultTransfer)
.then(response => console.log('Consultation transfer to queue agent completed'))
.catch(error => console.error('Failed to complete queue consultation transfer:', error));
Declines the incoming task. This will reject the task and notify the routing system. For voice calls, this is equivalent to declining the incoming call.
Promise
Error if the decline operation fails
// Decline an incoming task
task.decline()
.then(() => console.log('Task declined successfully'))
.catch(error => console.error('Failed to decline task:', error));
Ends the task/interaction with the customer. Emits task:end event when successful. If task requires wrap-up, this will be indicated in the task:end event data.
Promise
Error if ending task fails
// Set up task end event handler
task.on(TASK_EVENTS.TASK_END, (data) => {
console.log('Task ended:', task.data.interactionId);
if (data.wrapUpRequired) {
// Show wrap-up form
showWrapupForm();
} else {
// Clean up and prepare for next task
cleanupTask();
}
});
// End the task
try {
await task.end();
console.log('Task end request successful');
} catch (error) {
console.error('Failed to end task:', error);
// Handle error (e.g., show error message, retry option)
}
function showWrapupForm() {
// Show wrap-up UI with required codes
document.getElementById('wrapup-form').style.display = 'block';
}
function cleanupTask() {
// Reset UI state
document.getElementById('active-task').style.display = 'none';
document.getElementById('controls').style.display = 'none';
}
Ends an ongoing consultation session for the task. This terminates the consultation while maintaining the original customer connection.
Configuration for ending the consultation containing:
Promise
Error if ending consultation fails or invalid parameters provided
// End a direct agent consultation
const consultEndPayload = {
isConsult: true,
taskId: 'task123'
};
task.endConsult(consultEndPayload)
.then(response => console.log('Consultation ended successfully'))
.catch(error => console.error('Failed to end consultation:', error));
// End a queue consultation
const queueConsultEndPayload = {
isConsult: true,
taskId: 'task123',
queueId: 'queue123'
};
task.endConsult(queueConsultEndPayload)
.then(response => console.log('Queue consultation ended'))
.catch(error => console.error('Failed to end queue consultation:', error));
Puts the current task/interaction on hold. Emits task:hold event when successful. For voice tasks, this mutes the audio.
Promise
Error if hold operation fails
// Set up hold event handler
task.on(TASK_EVENTS.TASK_HOLD, () => {
console.log('Task is now on hold');
// Update UI to show hold state (e.g., enable resume button, show hold indicator)
document.getElementById('resume-btn').disabled = false;
document.getElementById('hold-indicator').style.display = 'block';
});
// Place task on hold
try {
await task.hold();
console.log('Successfully placed task on hold');
} catch (error) {
console.error('Failed to place task on hold:', error);
// Handle error (e.g., show error message, reset UI state)
}
Pauses the recording for the current voice task. Emits task:recordingPaused event when successful.
Promise
Error if pause recording fails
// Set up recording events
task.on(TASK_EVENTS.TASK_RECORDING_PAUSED, () => {
console.log('Recording paused');
// Update UI to show recording paused state
document.getElementById('recording-status').textContent = 'Recording Paused';
document.getElementById('pause-recording-btn').style.display = 'none';
document.getElementById('resume-recording-btn').style.display = 'block';
});
task.on(TASK_EVENTS.TASK_RECORDING_PAUSE_FAILED, (error) => {
console.error('Failed to pause recording:', error);
// Show error to agent
});
// Pause recording
try {
await task.pauseRecording();
console.log('Pause recording request sent');
} catch (error) {
console.error('Error sending pause recording request:', error);
// Handle error
}
Resumes the task/interaction that was previously put on hold. Emits task:resume event when successful. For voice tasks, this restores the audio.
Promise
Error if resume operation fails
// Set up resume event handler
task.on(TASK_EVENTS.TASK_RESUME, () => {
console.log('Task resumed from hold');
// Update UI to show active state
document.getElementById('hold-btn').disabled = false;
document.getElementById('hold-indicator').style.display = 'none';
});
// Resume task from hold
try {
await task.resume();
console.log('Successfully resumed task from hold');
} catch (error) {
console.error('Failed to resume task:', error);
// Handle error (e.g., show error message)
}
Resumes the recording for the voice task that was previously paused. Emits task:recordingResumed event when successful.
Configuration for resuming recording:
Promise
Error if resume recording fails
// Set up recording resume events
task.on(TASK_EVENTS.TASK_RECORDING_RESUMED, () => {
console.log('Recording resumed');
// Update UI to show active recording state
document.getElementById('recording-status').textContent = 'Recording Active';
document.getElementById('pause-recording-btn').style.display = 'block';
document.getElementById('resume-recording-btn').style.display = 'none';
});
task.on(TASK_EVENTS.TASK_RECORDING_RESUME_FAILED, (error) => {
console.error('Failed to resume recording:', error);
// Show error to agent
});
// Resume recording
try {
const resumePayload = {
autoResumed: false // Set to true if triggered by system
};
await task.resumeRecording(resumePayload);
console.log('Resume recording request sent');
} catch (error) {
console.error('Error sending resume recording request:', error);
// Handle error
}
Agent can mute/unmute their microphone during a WebRTC task. This method toggles between muted and unmuted states for the local audio stream.
Promise
Error if toggling mute state fails or audio stream is not available
// Toggle mute state
task.toggleMute()
.then(() => console.log('Mute state toggled successfully'))
.catch(error => console.error('Failed to toggle mute:', error));
Transfer the task to an agent directly or to a queue. This is a blind transfer that immediately redirects the task to the specified destination.
Transfer configuration containing:
Promise
Error if transfer fails or invalid parameters provided
// Transfer to a queue
const queueTransferPayload = {
to: 'salesQueue123',
destinationType: DESTINATION_TYPE.QUEUE
};
task.transfer(queueTransferPayload)
.then(response => console.log('Task transferred to queue successfully'))
.catch(error => console.error('Failed to transfer to queue:', error));
// Transfer to an agent
const agentTransferPayload = {
to: 'agentId123',
destinationType: DESTINATION_TYPE.AGENT
};
task.transfer(agentTransferPayload)
.then(response => console.log('Task transferred to agent successfully'))
.catch(error => console.error('Failed to transfer to agent:', error));
Updates the task data with new information
New task data to merge with existing data
If true, completely replace data instead of merging
The updated task instance
task.updateTaskData(newData);
task.updateTaskData(newData, true); // completely replace data
Wraps up the task/interaction with the customer. This is called after task:end event if wrapUpRequired is true. Emits task:wrappedup event when successful.
WrapupPayLoad containing:
Promise
Error if task data is unavailable, auxCodeId is missing, or wrapUpReason is missing
// Set up wrap-up events
task.on(TASK_EVENTS.TASK_WRAPUP, () => {
console.log('Task ready for wrap-up');
// Show wrap-up form
document.getElementById('wrapup-form').style.display = 'block';
});
task.on(TASK_EVENTS.TASK_WRAPPEDUP, () => {
console.log('Task wrap-up completed');
// Clean up UI
document.getElementById('wrapup-form').style.display = 'none';
});
// Submit wrap-up
try {
const wrapupPayload = {
auxCodeId: selectedCode, // e.g., 'ISSUE_RESOLVED'
wrapUpReason: 'Customer issue resolved successfully'
};
await task.wrapup(wrapupPayload);
console.log('Successfully submitted wrap-up');
} catch (error) {
console.error('Failed to submit wrap-up:', error);
// Handle validation errors
if (error.message.includes('required')) {
// Show validation error to agent
}
}
Private
reconcilePrivate
setup
Task class represents a contact center task/interaction that can be managed by an agent. This class provides all the necessary methods to manage tasks in a contact center environment, handling various call control operations and task lifecycle management.
Key events emitted by Task instances (see TASK_EVENTS for details):
Task Lifecycle:
Media & Controls:
Consultation & Transfer:
Recording:
Implements
Example