Amazon Q in Connect, an LLM-enhanced evolution of Amazon Connect Wisdom. The Amazon Q Connect JavaScript library (QConnectJS) gives you the power to build your own Amazon Q Connect widget.
The library uses an Amazon Connect authentication token to make API calls to Amazon Q Connect and supports all Amazon Q Connect Agent Assistant
functionality. For example, you can manually query knowledge documents, get knowledge content, or start generating automated suggestions.
QConnectJS supports the following APIs:
- QueryAssistant
- GetContact
- GetRecommendations
- NotifyRecommendationsReceived
- GetContent
- SearchSessions
- ListIntegrationAssociations
Note that this library must be used in conjunction with amazon-connect-streams.
For more advanced features, all Amazon Q Connect functionality is accessible using the public API. For example, you can create an assistant and a knowledge base. Check out Amazon Q Connect available via the AWS CLI.
To learn more about Amazon Q Connect and its capabilities, please check out the Amazon Q Connect User Guide.
To learn more about Amazon Connect and its capabilities, please check out the Amazon Connect User Guide.
The first step in setting up your Amazon Connect contact center is to create a virtual contact center instance. Each instance contains all the resources and settings related to your contact center. Follow the Get started with Amazon Connect user guide to get started.
To utilize QConnectJS you should start by enabling Amazon Q Connect for your Amazon Connect instance. Follow the Enable Amazon Q Connect user guide to get started.
All domains looking to integrate with Amazon Connect and Amazon Q Connect must be explicitly allowed for cross-domain access to the instance. For example, to integrate with your custom agent application, you must place your agent application domain in an allow list. To allow list a domain URL follow the app integration guide.
- Allowlisted domains must be HTTPS.
- All of the pages that attempt to initialize the QConnectJS library must be hosted on domains that are allowlisted.
npm install amazon-q-connectjs
$ git clone https://github.com/aws/amazon-q-connectjs
cd amazon-q-connectjs
npm install
npm run bundle
Find build artifacts in the release
directory. This will generate a file called amazon-q-connectjs.js
and a minified version amazon-q-connectjs-min.js
. This is the full QConnectJS client which you will want to include in your page.
amazon-q-connectjs
is available on NPM but if you'd like to download it here, you can find build artificacts in the release directory.
amazon-q-connectjs
is also available on open source CDNs. If you'd like to load build artifacts from a CDN, you can use either of the script tags below.
<script src="https://cdn.jsdelivr.net/npm/amazon-q-connectjs@1/release/amazon-q-connectjs.js"></script>
<script src="https://cdn.jsdelivr.net/npm/amazon-q-connectjs@1/release/amazon-q-connectjs-min.js"></script>
Initializing the QConnectJS client is the fist step to verify that you have everything setup correctly.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="connect-streams-min.js"></script>
<script type="text/javascript" src="amazon-q-connectjs-min.js"></script>
</head>
<!-- Add the call to init() as an onload so it will only run once the page is loaded -->
<body onload="init()">
<div id='ccp-container' style="width: 400px; height: 800px;"></div>
<script type="text/javascript">
const instanceUrl = 'https://my-instance-domain.awsapps.com/connect';
function init() {
// Initialize StreamsJS API
connect.agentApp.initApp(
'ccp',
'ccp-container',
`${instanceUrl}/ccp-v2/`,
{
ccpParams: {
style: 'width:400px; height:600px;',
}
}
);
// Initialize QConnectJS client with either "QConnectClient" or "Client"
const qConnectClient = new connect.qconnectjs.QConnectClient({
instanceUrl,
});
const qConnectClient = new connect.qconnectjs.Client({
instanceUrl: instanceUrl, // REQUIRED
endpoint: "https://my-instance-domain.awsapps.com/connect/api", // optional, defaults to '<instanceUrl>'
callSource: "agent-app", // optional, defaults to 'agent-app'
serviceId: 'AmazonQConnect', // optional, defaults to 'AmazonQConnect'
maxAttempts: 3, // optional, defaults to 3
logger: {}, // optional, if provided overrides default logger
headers: {}, // optional, if provided overrides request headers
requestHandler: {}, // optional, if provided overrides the default request handler
});
}
</script>
</body>
</html>
The QConnectJS client integrates with Connect by loading the pre-built Amazon Q Connect widget located at <instanceUrl>/wisdom-v2
into an iframe and placing it into a container div. API requests are funneled through this widget and made available to your JS client code.
instanceUrl
: The Connect instance url.endpoint
: Optional, set to override the Connect endpoint to use.callSource
: Optional, set to override the call source identifier on requests.headers
: This object is optional and allows overriding the headers provided to the HTTP handler.logger
: This object is optional and allows overriding the default Logger for logging debug/info/warn/error messages.maxAttempts
: Optional, set to specify how many times a request will be made at most in case of retry.requestHandler
: This object is optional and allows overriding the default request handler.serviceId
: Optional, set to override the unique service identifier on requests.
QConnectJS is modularized by client and commands.
To send a request, you only need to import the QConnectClient
and
the commands you need, for example GetRecommendations
:
// ES5 example
const { Client, GetRecommendations } = require("amazon-q-connectjs");
// ES6+ example
import { Client, GetRecommendations } from "amazon-q-connectjs";
The QConnectJS client can also send requests using convenience methods. However, it results in a bigger bundle size.
import { QConnectClient } from "amazon-q-connectjs";
const qConnectClient = new QConnectClient({
instanceUrl: "https://your-connect-instance.my.connect.aws",
});
// async/await.
try {
const response = await qConnectClient.getRecommendations(params);
// process response.
} catch (error) {
// error handling.
}
// Promises.
qConnectClient
.getRecommendations(params)
.then((response) => {
// process response.
})
.catch((error) => {
// error handling.
});
To send a request, you:
- Initiate the client with the desired configuration (e.g.
instanceUrl
,endpoint
). - call the desired API
const qConnectClient = new QConnectClient({
instanceUrl: "https://your-connect-instance.my.connect.aws",
});
qConnectClient.getRecommendations({
// input parameters
});
All API calls through QConnectJS return a promise. The promise resolves/rejects to provide the response from the API call.
We recommend using the await operator.
// async/await.
try {
const response = await qConnectClient.getRecommendations({
// input parameters
});
// process response.
} catch (error) {
// error handling.
} finally {
// finally.
}
async
-await
is clean, concise, intuitive, easy to debug and has better error handling
as compared to using Promise chains.
You can also use Promise chaining.
qConnectClient.getRecommendations({
// input parameters
}).then((response) => {
// process response.
}).catch((error) => {
// error handling.
}).finally(() => {
// finally.
});
Performs a manual search against the specified assistant. To retrieve recommendations for an assistant, use GetRecommendations. For more information check out the QueryAssistant API reference.
assistantId
: The identifier of the Amazon Q Connect assistant. Can be either the ID or the ARN. URLs cannot contain the ARN.queryText
: The text to search for.maxResults
: The maximum number of results to return per page.nextToken
: The token for the next set of results. Use the value returned in the previous response in the next request to retrieve the next set of results.
- The
assistantId
can be retrieved by using theListIntegrationAssociations
API provided by QConnectJS to look up theassistant
andknowledge base
that has been configured for Amazon Q Connect. See ListIntegrationAssociations for more information.
If the action is successful, the service sends back an HTTP 200 response.
{
"nextToken": "string",
"results": [
{
"document": {
"contentReference": {
"contentArn": "string",
"contentId": "string",
"knowledgeBaseArn": "string",
"knowledgeBaseId": "string"
},
"excerpt": {
"highlights": [
{
"beginOffsetInclusive": "number",
"endOffsetExclusive": "number"
}
],
"text": "string"
},
"title": {
"highlights": [
{
"beginOffsetInclusive": "number",
"endOffsetExclusive": "number"
}
],
"text": "string"
}
},
"relevanceScore": "number",
"resultId": "string"
}
]
}
const queryAssistantCommand = new QueryAssistant({
assistantId: 'b5b0e4af-026e-4472-9371-d171a9fdf75a',
maxResults: 10,
queryText: 'cancel order',
});
try {
const response = await qConnectClient.call(queryAssistantCommand);
// process response.
} catch (error) {
// error handling.
}
Retrieves contact details, including the Amazon Q Connect session ARN
, for a specified contact.
awsAccountId
: The identifier of the AWS account. You can find the awsAccountId in the ARN of the instance.InstanceId
: The identifier of the Amazon Connect instance. You can find the instanceId in the ARN of the instance.contactId
: The identifier of the Connect contact. Can be either the ID or the ARN. URLs cannot contain the ARN.
- One of the request parameters of the
GetContact
API is the Amazon ConnectcontactId
. The StreamsJS Contact API provides event subscription methods and action methods which can be called on behalf of a Contact and used to retrieve the Amazon ConnectcontactId
. See StreamsJS Integration below for more information.
If the action is successful, the service sends back an HTTP 200 response.
{
"contactId": "string",
"contactState": "string",
"contactSchemaVersion": "number",
"channel": "string",
"targetQueueResourceId": "string",
"agentResourceId": "string",
"targetAgentResourceId": "string",
"attributes": {},
"participants": [],
"contactFeature": {
"loggingEnabled": "boolean",
"textToSpeechFeatures": {},
"voiceIdFeatures": {},
"wisdomFeatures": {
"wisdomConfig": {
"sessionArn": "string"
}
}
},
"routingAttributes": {},
"languageCode": "string",
"channelContext": {},
}
const getContactCommand = new GetContact({
awsAccountId: 'b5b0e4af-026e-4472-9371-d171a9fdf75a',
instanceId: 'b5b0e4af-026e-4472-9371-d171a9fdf75a',
contactId: 'b5b0e4af-026e-4472-9371-d171a9fdf75a',
});
try {
const response = await qConnectClient.call(getContactCommand);
// process response.
} catch (error) {
// error handling.
}
Retrieves recommendations for the specified session. To avoid retrieving the same recommendations in subsequent calls, use NotifyRecommendationsReceived. This API supports long-polling behavior with the waitTimeSeconds
parameter. Short poll is the default behavior and only returns recommendations already available. To perform a manual query against an assistant, use the QueryAssistant API. For more information check out the GetRecommendations API reference.
assistantId
: The identifier of the Amazon Q Connect assistant. Can be either the ID or the ARN. URLs cannot contain the ARN.maxResult
: The maximum number of results to return per page.sessionId
: The identifier of the session. Can be either the ID or the ARN. URLs cannot contain the ARN.waitTimeSeconds
: The duration (in seconds) for which the call waits for a recommendation to be made available before returning. If a recommendation is available, the call returns sooner than WaitTimeSeconds. If no messages are available and the wait time expires, the call returns successfully with an empty list.
- The
assistantId
can be retrieved by using theListIntegrationAssociations
API provided by QConnectJS to look up theassistant
andknowledge base
that has been configured for Amazon Q Connect. See ListIntegrationAssociations for more information. - The
session ARN
can be retrieved by used theGetContact
API provided by QConnectJS to look up thesession
associated with a given activecontact
. See GetContact for more information. - To avoid retrieving the same recommendations on subsequent calls, the
NotifyRecommendationsReceived
API should be called after each response. See NotifyRecommendationsReceived for more information.
{
"recommendations": [
{
"document": {
"contentReference": {
"contentArn": "string",
"contentId": "string",
"knowledgeBaseArn": "string",
"knowledgeBaseId": "string"
},
"excerpt": {
"highlights": [
{
"beginOffsetInclusive": "number",
"endOffsetExclusive": "number"
}
],
"text": "string"
},
"title": {
"highlights": [
{
"beginOffsetInclusive": "number",
"endOffsetExclusive": "number"
}
],
"text": "string"
}
},
"recommendationId": "string",
"relevanceLevel": "string",
"relevanceScore": "number"
}
]
}
const getRecommendationsCommand = new GetRecommendations({
assistantId: 'b5b0e4af-026e-4472-9371-d171a9fdf75a',
sessionId: '9f2b6fab-9200-46d8-977a-c89be3b34639',
maxResults: 10,
waitTimeSeconds: 5,
});
try {
const response = await qConnectClient.call(getRecommendationsCommand);
// process response.
} catch (error) {
// error handling.
}
Removes the specified recommendations from the specified assistant's queue of newly available recommendations. You can use this API in conjunction with GetRecommendations and a waitTimeSeconds
input for long-polling behavior and avoiding duplicate recommendations. For more information check out the NotifyRecommendationsReceived API reference.
assistantId
: The identifier of the Amazon Q Connect assistant. Can be either the ID or the ARN. URLs cannot contain the ARN.sessionId
: The identifier of the session. Can be either the ID or the ARN. URLs cannot contain the ARN.recommendationIds
: The identifier of the recommendations.
- The
assistantId
can be retrieved by using theListIntegrationAssociations
API provided by QConnectJS to look up theassistant
andknowledge base
that has been configured for Amazon Q Connect. See ListIntegrationAssociations for more information. - The
session ARN
can be retrieved by used theGetContact
API provided by QConnectJS to look up thesession
associated with a given activecontact
. See GetContact for more information.
{
"errors": [
{
"message": "string",
"recommendationId": "string"
}
],
"recommendationIds": [ "string" ]
}
const notifyRecommendationsReceivedCommand = new NotifyRecommendationsReceived({
assistantId: 'b5b0e4af-026e-4472-9371-d171a9fdf75a',
sessionId: '9f2b6fab-9200-46d8-977a-c89be3b34639',
recommendationIds: [
'f9b5fa90-b3ce-45c9-9967-582c87074864',
],
});
try {
const response = await qConnectClient.call(notifyRecommendationsReceivedCommand);
// process response.
} catch (error) {
// error handling.
}
Retrieves content, including a pre-signed URL to download the content. The contentId
and knowledgeBaseId
request parameters are part of search results response syntax when calling QueryAssistant
or recommendations response syntax when calling GetRecommendations
. For more information check out the GetContent API reference.
contentId
: The identifier of the content. Can be either the ID or the ARN. URLs cannot contain the ARN.knowledgeBaseId
: The identifier of the knowledge base. Can be either the ID or the ARN. URLs cannot contain the ARN.
- The
contentId
andknowledgeBaseId
can be found by using either theQueryAssistant
orGetRecommendations
APIs to retrieve knowledge documents. Each of the documents from either response will include acontentReference
. See QueryAssistant and GetRecommendations for more information.
const getContentCommand = new GetContent({
contentId: '9f2b6fab-9200-46d8-977a-c89be3b34639',
knowledgeBaseId: 'f9b5fa90-b3ce-45c9-9967-582c87074864',
});
try {
const response = await qConnectClient.call(getContentCommand);
// process response.
} catch (error) {
// error handling.
}
Searches for sessions. For more information check out the SearchSessions API reference.
assistantId
: The identifier of the Amazon Q Connect assistant. Can be either the ID or the ARN. URLs cannot contain the ARN.searchExpression
: The search expression to filter results.maxResults
: The maximum number of results to return per page.nextToken
: The token for the next set of results. Use the value returned in the previous response in the next request to retrieve the next set of results.
- The
assistantId
can be retrieved by using theListIntegrationAssociations
API provided by QConnectJS to look up theassistant
andknowledge base
that has been configured for Amazon Q Connect. See ListIntegrationAssociations for more information.
{
"nextToken": "string",
"sessionSummaries": [
{
"assistantArn": "string",
"assistantId": "string",
"sessionArn": "string",
"sessionId": "string"
}
]
}
const searchSessionsCommand = new SearchSessions({
assistantId: 'b5b0e4af-026e-4472-9371-d171a9fdf75a',
searchExpression: {
filters: [
{
operator: 'equals',
field: 'name',
value: '249bbb30-aede-42a8-be85-d8483c317686',
}
]
}
});
try {
const response = await qConnectClient.call(searchSessionsCommand);
// process response.
} catch (error) {
// error handling.
}
Retrieves Connect integrations, including assistant and knowledge base integrations. For more information check out the ListIntegrationAssociations API reference.
InstanceId
: The identifier of the Amazon Connect instance. You can find the instanceId in the ARN of the instance.IntegrationType
: The integration type.MaxResults
: The maximum number of results to return per page.nextToken
: The token for the next set of results. Use the value returned in the previous response in the next request to retrieve the next set of results.
- One of the request parameters of the
ListIntegrationAssociations
API is the Amazon ConnectinstanceId
. The StreamsJS Agent API provides event subscription methods and action methods which can be called on behalf of the agent and used to retrieve the Amazon ConnectinstanceId
. See StreamsJS Integration below for more information.
If the action is successful, the service sends back an HTTP 200 response.
{
"IntegrationAssociationSummaryList": [
{
"InstanceId": "string",
"IntegrationArn": "string",
"IntegrationAssociationArn": "string",
"IntegrationAssociationId": "string",
"IntegrationType": "string",
"SourceApplicationName": "string",
"SourceApplicationUrl": "string",
"SourceType": "string"
}
],
"NextToken": "string"
}
const listIntegrationAssociationsCommand = new ListIntegrationAssociations({
InstanceId: 'b5b0e4af-026e-4472-9371-d171a9fdf75a',
IntegrationType: 'WISDOM_ASSISTANT',
MaxResults: 10,
});
try {
const response = await qConnectClient.call(listIntegrationAssociations);
// process response.
} catch (error) {
// error handling.
}
In order to use QConnectJS, the library must be used in conjunction with amazon-connect-streams. Integrating with Amazon Connect Streams provides enables you to handle agent and contact state events directly through an object oriented event driven interface.
The StreamsJS Agent API provides event subscription methods and action methods which can be called on behalf of the agent. For more information check out the StreamsJS Agent API reference.
The StreamsJS Agent API can be used to retrieve the Amazon Connect instanceId
using the Agent routingProfileId
. The routing profile contains the following fields:
channelConcurrencyMap
: Seeagent.getChannelConcurrency()
for more info.defaultOutboundQueue
: The default queue which should be associated with outbound contacts. Seequeues
for details on properties.name
: The name of th routing profile.queues
: The queues contained in the routing profile. Each queue object has the following properties:name
: The name of the queue.queueARN
: The ARN of the queue.queueId
: Alias for thequeueARN
.
routingProfileARN
: The routing profile ARN.routingProfileId
: Alias for theroutingProfileARN
.
const routingProfile = agent.getRoutingProfile();
const instanceId = routingProfile.routingProfileId.match(
/instance\/([0-9a-fA-F|-]+)\//
)[1];
The StreamsJS Contact API provides event subscription methods and action methods which can be called on behalf of a contact. For more information check out the StreamsJS Contact API reference.
The StreamsJS Contact API can be used to retrieve the Amazon Connect contactId
using the Contact getContactId
method.
const contactId = contact.getContactId();
When the service returns an exception, the error will include the exception information.
try {
const data = await client.call(command);
// process data.
} catch (error) {
console.log(error);
// error handling.
}
See CONTRIBUTING for more information.
QConnectJS is distributed under the Apache License, Version 2.0, see LICENSE for more information.