Closed jjwilliams42 closed 1 year ago
Hi, could you try to steps below and see if the issue is still there?
https://github.com/amazon-connect/amazon-connect-chat-ui-examples/issues/108#issuecomment-1571103916
Hi @jjwilliams42, are you having an issue passing an attribute from the chat widget to the contact flow? Could you try the steps listed below and let us know if this address the issue?
Thanks, Spencer
When initializing the chat with a StartChatContact request, you can pass custom attributes to the the contact flow.
flowchart LR
START["`Chat Widget
StartChat Request`"] --> B["`Lambda (AWS-SDK)
connect.startChatContact`"];
B --> C["`Amazon Connect
StartChatContact API`"];
C --> END["`Amazon Connect
Contact Flow`"];
StartChatContact
API - DocumentationstartChatContactAPI
Lambda - CloudFormation TemplateAmazonConnectChatWidget
, pass in custom contactAttributes
to the ChatInterface.initiateChat()
method. This will pass "Attributes"
key in the request body// https://github.com/amazon-connect/amazon-connect-chat-interface/blob/master/src/components/Chat/ChatInitiator.js
connect.ChatInterface.initiateChat({
name: customerName,
region: ${region},
contactFlowId: "${contactFlowId}",
instanceId: "${instanceId}",
apiGatewayEndpoint: "${apiGatewayEndpoint}",
contactAttributes: JSON.stringify({
"customerName": customerName,
"customAttribute": "myCustomAttribute". // <------ CUSTOM ATTRIBUTE HERE
}),
},successHandler, failureHandler)
StartChatContact
call, make sure to forward body["Attributes"]
to connect.startChatContact()
/*
Example `startChatContactAPI` lambda making a call to the Amazon Connect public StartChatContact API
LINK: https://github.com/amazon-connect/amazon-connect-chat-ui-examples/blob/master/cloudformationTemplates/startChatContactAPI/js/startChatContact.js
1) Chat Widget will make request to this Lambda
2) Lambda will forward the request to the Amazon Connect Backend
*/
var AWS = require('aws-sdk');
AWS.config.update({region: process.env.REGION});
var connect = new AWS.Connect();
exports.handler = (event, context, callback) => {
console.log("Received event: " + JSON.stringify(event));
var body = JSON.parse(event["body"]);
startChatContact(body).then((startChatResult) => {
callback(null, buildSuccessfulResponse(startChatResult));
}).catch((err) => {
console.log("caught error " + err);
callback(null, buildResponseFailed(err));
});
};
function startChatContact(body) {
return new Promise(function (resolve, reject) {
var startChat = {
"InstanceId": body["InstanceId"],
"ContactFlowId": body["contactFlowId"],
"Attributes": {
"customerName": body["ParticipantDetails"]["DisplayName"],
// ...
...body["Attributes"] // <------ CUSTOM ATTRIBUTE HERE
},
"ParticipantDetails": {
"DisplayName": body["ParticipantDetails"]["DisplayName"]
},
};
// https://docs.aws.amazon.com/connect/latest/APIReference/API_StartChatContact.html
connect.startChatContact(startChat, function(err, data) {
if (err) {
console.log("Error starting the chat.", err);
reject(err);
} else {
console.log("Start chat succeeded with the response: " + JSON.stringify(data));
resolve(data);
}
});
});
}
Closing issue. Feel free to re-open if you are still experiencing any issues
When initializing a chat, the contact attributes are never saved on the contact when looking at their record in Amazon Connect.
Here is our initialization code:
Here are the contact attributes that get stored in Amazon Connect (all of these came from the flow except customerName which came from chat):