AmazonConnectTaskJS
About
The Amazon Connect Task javascript library (TaskJS) gives you the power to handle task contacts when used together with Amazon Connect Streams.
Learn More
To learn more about Amazon Connect and its capabilities, please check out
the Amazon Connect User Guide.
Getting Started
Using TaskJS from Github
$ git clone https://github.com/amazon-connect/amazon-connect-taskjs
Including TaskJS
Amazon Connect Streams is required to use TaskJS. Ensure you import TaskJS after Streams.
TaskJs v2.0 requires Streams v2.2 or later.
Building
- Install latest LTS version of NodeJS
- Checkout this package into workspace and navigate to root folder
npm install
- To build (non-minified):
npm run devo for a non-minified build.
- Find build artifacts in dist directory.
- To build (minified):
npm run release for a minified build.
- Find build artifacts in dist directory.
- To run unit tests:
- To clean node_modules:
- To make webpack watch all files:
Find build artifacts in dist directory - This will generate a file called amazon-connect-task.js - this is the full Connect TaskJS API which you will want to include in your page.
Usage:
TaskJS provides a taskSession instance for each task contact. You can access the taskSession by calling the getMediaController method on a taskConnection. getMediaController returns a promise that resolves with a taskSession instance.
For example:
taskConnection.getMediaController().then((taskSession) => { });
Event Handlers
Each of the following event handlers will pass a message object to the callback function containing the following fields:
AbsoluteTime: UTC timestamp of when the event occurred.
ContentType: One of the following strings depending on the event:
application/vnd.amazonaws.connect.event.transfer.initiated
application/vnd.amazonaws.connect.event.transfer.succeeded
application/vnd.amazonaws.connect.event.transfer.failed
application/vnd.amazonaws.connect.event.expire.warning
application/vnd.amazonaws.connect.event.expire.complete
Id: The contact ID
InitialContactId: The initial contact id.
taskSession.onTransferInitiated
Subscribe a method to be invoked when the server has initiated the task transfer.
taskSession.onTransferInitiated((message) => console.log("Transfer has initiated"))
taskSession.onTransferSucceeded
Subscribe a method to be invoked when the task transfer has succeeded.
taskSession.onTransferSucceeded((message) => console.log("Transfer has succeeded"))
taskSession.onTransferFailed
Subscribe a method to be invoked when the task transfer has failed.
taskSession.onTransferFailed((message) => console.log("Transfer has failed"))
taskSession.onTaskExpiring
Subscribe a method to be invoked two hours before the task expires.
taskSession.onTaskExpiring((message) => console.log("Task will expire in two hours"))
taskSession.onTaskExpired
Subscribe a method to be invoked when the task has expired.
taskSession.onTaskExpired((message) => console.log("Task has expired"))
taskSession.onMessage
Subscribe a method to be invoked when any one of the above events has occurred.
taskSession.onMessage((message) => console.log("The following event has occurred:", message.ContentType))
Methods
agent.createTask()
Create a new task.
const newTask = {
name: "string",
description: "string",
endpoint: endpointObject,
taskTemplateId: "string",
previousContactId: "string",
references: {
"reference name 1": {
type: "URL"
value: "https://www.amazon.com"
},
"reference name 2": {
type: "EMAIL"
value: "example@abc.com"
},
"reference name 3": {
type: "NUMBER"
value: 1000
},
"reference name 4": {
type: "DATE",
value: 1649961230
},
"reference name 5": {
type: "STRING"
value: "example@abc.com"
}
},
scheduledTime: "number"
};
agent.createTask(newTask, {
success: function(data) { console.log("Created a task with contact id: ", data.contactId) },
failure: function(err) { }
});
agent.updateContact()
Update a task contact created from a template.
const updatedTaskData = {
contactId: "string",
name: "string",
description: "string",
references: {
"reference name": {
type: "NUMBER"
value: 1001
}
}
};
agent.updateContact(updatedTaskData, {
success: function() { console.log("The task updated successfully") },
failure: function(err) { }
});
agent.listTaskTemplates()
Load a list of task templates that belong to a connect instance
const queryParams = {
status: 'active',
maxResults: 50
};
agent.listTaskTemplates(queryParams, {
success: function(data) { console.log("List of task templates loaded successfully", data) },
failure: function(err) { }
});
agent.getTaskTemplate()
Load a template data, including fields, default values and constraints
const templateParams = {
id: 'string',
version: 'string'
};
agent.getTaskTemplate(templateParams, {
success: function(data) { console.log("Template data loaded successfully", templateParams.id, data) },
failure: function(err) { }
});
Enumerations
connect.ReferenceType
This enumeration lists the different reference types for a task. Currently supported types: URL, EMAIL, NUMBER, STRING, DATE.
ReferenceType.URL: A URL reference.
Security
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.