Comments (6)
The react app is calling an API Gateway method in your AWS account, which invokes a Lambda function, which calls the StartChatContact that you linked to. The place where the Lambda function makes its call (assuming you're using the startChatContact backend from the Readme steps) is at https://github.com/amazon-connect/amazon-connect-chat-ui-examples/blob/master/cloudformationTemplates/startChatContactAPI/js/startChatContact.js#L30 - and it only passes body.ParticipantDetails.DisplayName to the Attributes parameter. You'd need to change the Lambda function to use the Attributes (or contactAttributes) parameter you're passing and send it into connect.startChatContact.
from amazon-connect-chat-ui-examples.
@coderjonny can you please confirm the lambda that is invoked by the API Gateway method? Is it the startChatContact backend function linked above?
Can you please share the code snippet for that Lambda function so we can confirm? Thank you.
from amazon-connect-chat-ui-examples.
Hi all, Team needs more time to investigate this, will provide updates on this issue after taking further look.
For now, can you confirm the backend setup that is being used?
If using the startChatContact
Lambda (like @lwarneminde explained), this code might be ignoring extra attributes, and you can update the lambda like so:
EXAMPLE DIFF: master...spenlep-attribute-diff-example-test
// cloudformationTemplates/startChatContactAPI/js/startChatContact.js
var AWS = require('aws-sdk');
AWS.config.update({region: process.env.REGION});
var connect = new AWS.Connect();
var startChat = {
"InstanceId": instanceId == "" ? process.env.INSTANCE_ID : instanceId,
"ContactFlowId": contactFlowId == "" ? process.env.CONTACT_FLOW_ID : contactFlowId,
"Attributes": {
"customerName": body["ParticipantDetails"]["DisplayName"],
+ "customAttribute": body["customAttributesPassedFromChatInterface"]["MyCustomAttribute"]
},
"ParticipantDetails": {
"DisplayName": body["ParticipantDetails"]["DisplayName"]
},
// Enable rich messaging: https://docs.aws.amazon.com/connect/latest/adminguide/enable-text-formatting-chat.html
...(!!body["SupportedMessagingContentTypes"] && { "SupportedMessagingContentTypes": body["SupportedMessagingContentTypes"] }),
// Set optional chat duration: https://docs.aws.amazon.com/connect/latest/APIReference/API_StartChatContact.html#connect-StartChatContact-request-ChatDurationInMinutes
...(!!body["ChatDurationInMinutes"] && { "ChatDurationInMinutes": body["ChatDurationInMinutes"] })
};
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);
}
});
Please feel free to post further question, team will continue to track issue.
Thanks,
Spencer
from amazon-connect-chat-ui-examples.
Passing Custom Attribute to Contact Flow
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`"];
Reference
StartChatContact
API - Documentation- Admin Guide - "Use Amazon Connect contact attributes"
- Example
startChatContactAPI
Lambda - CloudFormation Template
Configuration
- If using the GitHub
AmazonConnectChatWidget
, pass in customcontactAttributes
to theChatInterface.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)
- Update the lambda making the
StartChatContact
call, make sure to forwardbody["Attributes"]
toconnect.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);
}
});
});
}
- Consume the new attribute in the contact flow. Refer to the Admin Guide - "Use Amazon Connect contact attributes"
from amazon-connect-chat-ui-examples.
Hi @coderjonny, thank you for taking the time to raise this issue. Can you confirm if this has resolved unblocked your use case?
I have provided further explanation to enable passing a custom attribute in the startChatContact.js
lambda function. Team will update documentation to avoid further confusion.
If there is no further problem, going to resolve this issue. Let us know if you have any questions.
Thanks,
Spencer
from amazon-connect-chat-ui-examples.
Hi @spencerlepine ,
Yes, updating our lambda resolved our issue!
Thank you.
from amazon-connect-chat-ui-examples.
Related Issues (20)
- Update startChatContactAPI - ChatSDK.zip runtime HOT 2
- Update startChatContactAPI - start-chat-contact.zip runtime HOT 2
- Replace default "System_message" and "Bot" Values HOT 4
- Uncaught ReferenceError: enableAttachments is not defined HOT 2
- Why is apiGateway mandatory to run customChatWidget HOT 3
- Prebuilt Form is not working when we submit the form HOT 6
- Get Error code 403 access denied HOT 6
- Unable to change font size HOT 2
- amazon-connect-chat-interface.js uses new Function which throws CSP error HOT 5
- Pull Request #123 close bug. HOT 5
- Security Q - API/WAF HOT 3
- Issues with disconnect after chatSession.endChat HOT 2
- Facing issue while trying to setup AndroidChatExample HOT 2
- Cannot create amazon-connect-interactive-messages-example stack because of the Lambda runtime version HOT 3
- urlPreviewForAsyncChat requires updates HOT 2
- Unable to remove preChat form from customChatWidget HOT 5
- Problem with Custom widget window sizing HOT 1
- Having similar issue to #16 and #85. Must refresh the browser tab to get new widget window. HOT 1
- Prevent ChatWidget from disappearing after client clicks 'End Chat' HOT 2
- PersistentChat on Page Refresh HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amazon-connect-chat-ui-examples.