The Amazon Connect CustomerProfiles JavaScript library (CustomerProfilesJS) gives you the power to build your own CustomerProfiles widget.
The library uses Connect authentication token to make API calls to CustomerProfiles service. The client supports all CustomerProfile apis enabled on connect instance.
The client supports the following apis
For more details on the apis, check out CustomerProfiles available via the AWS CLI.
amazon-connect-customer-profiles is available from npmjs.com. If you'd like to download it here, you can use either of the files like dist/amazon-connect-customer-profiles*
.
Run npm run release to generate new release files.
$ git clone https://github.com/amazon-connect/amazon-connect-customer-profiles.git
$ cd amazon-connect-customer-profiles
$ npm install
$ npm run release
Find build artifacts in dist directory - This will generate a file called amazon-connect-customer-profiles.js
and the minified version of the same amazon-connect-customer-profiles-min.js
.
Install using npm
:
npm install amazon-connect-customer-profiles
The order of initialization matters:
connect-streams
javascript library before embedding amazon-connect-customer-profiles
.Connect CCP
before initializing CustomerProfilesClient
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="https://github.com/amazon-connect/amazon-connect-customer-profiles/raw/main/connect-streams-min.js"></script>
<script type="text/javascript" src="https://github.com/amazon-connect/amazon-connect-customer-profiles/raw/main/amazon-connect-customer-profiles-min.js"></script>
</head>
<body>
<div id="container-div" style="width: 400px; height: 800px;"></div>
<script type="text/javascript">
let instanceName = 'https://test.my.connect.aws';
// Initialize streams API
var containerDiv = document.getElementById("container-div");
connect.core.initCCP(
containerDiv,
...
);
// Initialize customerProfilesJS client
client = new connect.CustomerProfilesClient(instanceName);
</script>
</body>
</html>
CustomerProfilesJS client supports the following api methods.
Initialize the client
client = connect.CustomerProfilesClient(instanceName, endpoint);
CreateProfile - creates a standard profile.
client.createProfile({
"DomainName": "<DOMAIN_NAME>",
"FirstName": "<FIRST_NAME>"
});
UpdateProfile - Updates the properties of a profile. The ProfileId is required for updating a customer profile.
client.updateProfile({
"ProfileId": "<PROFILE_ID>",
"FirstName": "<FIRST_NAME>",
"LastName": "<LAST_NAME>",
"DomainName": "<DOMAIN_NAME>"
});
SearchProfile - Searches for profiles within a domain.
client.searchProfiles({
"DomainName": "<DOMAIN_NAME>",
"KeyName": "_profileId",
"Values": [ "<PROFILE_ID>" ]
});
AddProfileKey - Associates a new key value with a specific profile, such as a Contact Trace Record (CTR) ContactId.
client.addProfileKey({
"DomainName": "<DOMAIN_NAME>",
"ProfileId": "<PROFILE_ID>",
"KeyName": "_phone",
"Values": [ "<PHONE_NUMBER>" ]
});
ListProfileObjects - Returns a list of objects associated with a profile of a given ProfileObjectType.
client.listProfileObjects({
"DomainName": "<DOMAIN_NAME>",
"ObjectTypeName": "CTR",
"ProfileId": "<PROFILE_ID>",
"MaxResults": 10
});
ListAccountIntegrations - Lists all of the integrations associated to a specific URI in the AWS account.
client.listAccountIntegrations({
"Uri": "<URI>"
});
All api calls through the client returns a promise. The promise resolves/rejects to provide the results from the api call. 200 status api status code is resolved and all other status codes are rejected.
Client response contains the following fields
status
: api call status codestatusText
: api call status textdata
: api response data{
"status": 200,
"statusText": "OK",
"data": {<api_response>}
}
You can use Promise chaining to read results from client response.
client.createProfile({
"DomainName": "<DOMAIN_NAME>",
"FirstName": "<FIRST_NAME>"
}).then((res) => {
console.log('Success response: ' + JSON.stringify(res));
}).catch((errorResp) => {
console.log('Error response: ' + JSON.stringify(errorResp));
});
Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided
This indicates that the customer-profiles hidden widget used by the client is not loaded. Ensure user has successfully signed in to connect instance and reload the page.
See CONTRIBUTING for more information.
CustomerProfilesJS is distributed under the Apache License, Version 2.0, see LICENSE for more information.