Skip to content

Commit 94e8e40

Browse files
committed
Add mechanism to send an utterance after live chat has completed. Capture relevant connect id information and use as session attributes such that the end live chat utterance has a handle on connect attributes when the live chat completed. This is useful if implementing a post live chat survey.
1 parent 97d4e60 commit 94e8e40

File tree

10 files changed

+68
-15
lines changed

10 files changed

+68
-15
lines changed

build/release.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@ make "qbusiness-lambda-$VERSION.zip"
4646
cd ..
4747
cd dist
4848
make
49+
cp app.js lex-web-ui.js
50+
cp app.min.js lex-web-ui.min.js
51+
cp app.js.map lex-web-ui.js.map
4952

build/update-lex-web-ui-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const lexV2BotLocaleVoices = {
147147
'CONNECT_START_LIVE_CHAT_ICON',
148148
'CONNECT_END_LIVE_CHAT_LABEL',
149149
'CONNECT_END_LIVE_CHAT_ICON',
150+
'CONNECT_END_LIVE_CHAT_UTTERANCE',
150151
'CONNECT_TRANSCRIPT_MESSAGE_DELAY_IN_MSEC',
151152
'APP_DOMAIN_NAME',
152153
'UI_TOOLBAR_TITLE',

config/base.env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = {
2323
chatEndedMessage: process.env.CONNECT_CHAT_ENDED_MESSAGE,
2424
attachChatTranscript: process.env.CONNECT_ATTACH_CHAT_TRANSCRIPT,
2525
liveChatTerms: process.env.CONNECT_LIVE_CHAT_TERMS,
26+
endLiveChatUtterance: process.env.CONNECT_END_LIVE_CHAT_UTTERANCE,
2627
transcriptMessageDelayInMsec: process.env.CONNECT_TRANSCRIPT_MESSAGE_DELAY_IN_MSEC,
2728
},
2829
lex: {

config/env.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export CONNECT_START_LIVE_CHAT_LABEL ?= $()
3636
export CONNECT_START_LIVE_CHAT_ICON ?= $()
3737
export CONNECT_END_LIVE_CHAT_LABEL ?= $()
3838
export CONNECT_END_LIVE_CHAT_ICON ?= $()
39+
export CONNECT_END_LIVE_CHAT_UTTERANCE ?= $()
3940
export CONNECT_TRANSCRIPT_MESSAGE_DELAY_IN_MSEC ?= $()
4041
export BOT_INITIAL_TEXT ?= $()
4142
export BOT_INITIAL_SPEECH ?= $()

lex-web-ui/src/config/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ const configDefault = {
7676
liveChatTerms: 'live chat',
7777
// The delay to use between sending transcript blocks to connect
7878
transcriptMessageDelayInMsec: 150,
79+
// Utterance to send on end live chat
80+
endLiveChatUtterance: ''
7981
},
8082
lex: {
8183
// Lex V2 fields

lex-web-ui/src/store/actions.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ export default {
982982
return Promise.resolve();
983983
});
984984
}
985-
// If TalkDesk endpoint is available use
985+
// If TalkDesk endpoint is available use
986986
else if (context.state.config.connect.talkDeskWebsocketEndpoint) {
987987
liveChatSession = initTalkDeskLiveChat(context);
988988
return Promise.resolve();
@@ -1020,7 +1020,7 @@ export default {
10201020
if (context.state.config.connect.apiGatewayEndpoint) {
10211021
sendChatMessage(liveChatSession, message);
10221022
}
1023-
// If TalkDesk endpoint is available use
1023+
// If TalkDesk endpoint is available use
10241024
else if (context.state.config.connect.talkDeskWebsocketEndpoint) {
10251025
sendTalkDeskChatMessage(context, liveChatSession, message);
10261026

@@ -1032,22 +1032,22 @@ export default {
10321032
dialogState: context.state.lex.dialogState
10331033
},
10341034
);
1035-
}
1035+
}
10361036
}
10371037
},
10381038
requestLiveChatEnd(context) {
10391039
console.info('actions: endLiveChat');
10401040
context.commit('clearLiveChatIntervalId');
10411041
if (context.state.chatMode === chatMode.LIVECHAT && liveChatSession) {
1042-
1042+
10431043
// If Connect API Gateway Endpoint is set, use Connect
10441044
if (context.state.config.connect.apiGatewayEndpoint) {
10451045
requestLiveChatEnd(liveChatSession);
10461046
}
1047-
// If TalkDesk endpoint is available use
1047+
// If TalkDesk endpoint is available use
10481048
else if (context.state.config.connect.talkDeskWebsocketEndpoint) {
10491049
requestTalkDeskLiveChatEnd(context, liveChatSession, "agent");
1050-
}
1050+
}
10511051

10521052
context.dispatch('pushLiveChatMessage', {
10531053
type: 'agent',
@@ -1068,6 +1068,15 @@ export default {
10681068
},
10691069
liveChatSessionEnded(context) {
10701070
console.info('actions: liveChatSessionEnded');
1071+
console.info(`connect config is : ${context.state.config.connect}`);
1072+
if (context.state.config.connect.endLiveChatUtterance && context.state.config.connect.endLiveChatUtterance.length > 0) {
1073+
const message = {
1074+
type: context.state.config.ui.hideButtonMessageBubble ? 'button' : 'human',
1075+
text: context.state.config.connect.endLiveChatUtterance,
1076+
};
1077+
context.dispatch('postTextMessage', message);
1078+
console.info("dispatching request to send message");
1079+
}
10711080
liveChatSession = null;
10721081
context.commit('setLiveChatStatus', liveChatStatus.ENDED);
10731082
context.commit('setChatMode', chatMode.BOT);
@@ -1307,15 +1316,15 @@ export default {
13071316
Bucket: context.state.config.ui.uploadS3BucketName,
13081317
Key: documentKey,
13091318
};
1310-
1319+
13111320
s3.putObject(s3Params, function(err, data) {
13121321
if (err) {
13131322
console.log(err, err.stack); // an error occurred
13141323
context.commit('pushMessage', {
13151324
type: 'bot',
13161325
text: context.state.config.ui.uploadFailureMessage,
13171326
});
1318-
}
1327+
}
13191328
else {
13201329
console.log(data); // successful response
13211330
const documentObject = {

lex-web-ui/src/store/live-chat-handlers.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,24 @@ export const connectLiveChatSession = session =>
3535
return Promise.reject(error);
3636
}));
3737

38+
function recordSessionAttributes(context, chatDetails) {
39+
if (chatDetails && chatDetails.initialContactId) {
40+
context.commit("setLexSessionAttributeValue", { key: 'connect_initial_contact_id', value: chatDetails.initialContactId });
41+
}
42+
if (chatDetails && chatDetails.contactId) {
43+
context.commit("setLexSessionAttributeValue", { key: 'connect_contact_id', value: chatDetails.contactId });
44+
}
45+
if (chatDetails && chatDetails.participantId) {
46+
context.commit("setLexSessionAttributeValue", { key: 'connect_participant_id', value: chatDetails.participantId });
47+
}
48+
}
49+
3850
export const initLiveChatHandlers = (context, session) => {
3951
session.onConnectionEstablished((data) => {
4052
console.info('Established!', data);
53+
if (data && data.chatDetails) {
54+
recordSessionAttributes(context, data.chatDetails);
55+
}
4156
// context.dispatch('pushLiveChatMessage', {
4257
// type: 'agent',
4358
// text: 'Live Chat Connection Established',
@@ -48,6 +63,9 @@ export const initLiveChatHandlers = (context, session) => {
4863
const { chatDetails, data } = event;
4964
console.info(`Received message: ${JSON.stringify(event)}`);
5065
console.info('Received message chatDetails:', chatDetails);
66+
if (chatDetails) {
67+
recordSessionAttributes(context, chatDetails);
68+
}
5169
let type = '';
5270
switch (data.ContentType) {
5371
case 'application/vnd.amazonaws.connect.event.participant.joined':

src/config/lex-web-ui-loader-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"agentLeftMessage": "",
1111
"chatEndedMessage": "",
1212
"attachChatTranscript": "",
13+
"endLiveChatUtterance": "",
1314
"transcriptMessageDelayInMsec": ""
1415
}
1516
}

templates/codebuild-deploy.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ Parameters:
230230
Icon to use in menu and toolbar to end connect live chat
231231
Default: "call_end"
232232

233+
ConnectEndLiveChatUtterance:
234+
Type: String
235+
Description: >
236+
Optional utterance to send to bot after ending a live chat session
237+
Default: ''
238+
233239
ConnectTranscriptMessageDelayInMsec:
234240
Type: Number
235241
Description: >
@@ -839,6 +845,8 @@ Resources:
839845
Value: !Ref ConnectEndLiveChatLabel
840846
- Name: CONNECT_END_LIVE_CHAT_ICON
841847
Value: !Ref ConnectEndLiveChatIcon
848+
- Name: CONNECT_END_LIVE_CHAT_UTTERANCE
849+
Value: !Ref ConnectEndLiveChatUtterance
842850
- Name: CONNECT_TRANSCRIPT_MESSAGE_DELAY_IN_MSEC
843851
Value: !Ref ConnectTranscriptMessageDelayInMsec
844852
- Name: APP_USER_POOL_CLIENT_ID
@@ -987,6 +995,7 @@ Resources:
987995
ConnectStartLiveChatIcon: !Ref ConnectStartLiveChatIcon
988996
ConnectEndLiveChatLabel: !Ref ConnectEndLiveChatLabel
989997
ConnectEndLiveChatIcon: !Ref ConnectEndLiveChatIcon
998+
ConnectEndLiveChatUtterance: !Ref ConnectEndLiveChatUtterance
990999
ConnectTranscriptMessageDelayInMsec: !Ref ConnectTranscriptMessageDelayInMsec
9911000
WebAppBucket: !Ref WebAppBucket
9921001
LexV2BotId: !Ref LexV2BotId

templates/master.yaml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ Parameters:
486486
Icon to use in menu and toolbar to end connect live chat
487487
Default: "call_end"
488488

489+
ConnectEndLiveChatUtterance:
490+
Type: String
491+
Description: >
492+
Optional utterance to send to bot after ending a live chat session
493+
Default: ''
494+
489495
## CSS Configuration Options
490496
MessageTextColor:
491497
Type: String
@@ -686,6 +692,7 @@ Metadata:
686692
- ConnectStartLiveChatIcon
687693
- ConnectEndLiveChatLabel
688694
- ConnectEndLiveChatIcon
695+
- ConnectEndLiveChatUtterance
689696
- ConnectTranscriptMessageDelayInMsec
690697
- Label:
691698
default: CSS Customization Parameters
@@ -701,7 +708,7 @@ Metadata:
701708
default: Q Business Parameters
702709
Parameters:
703710
- AmazonQAppId
704-
- IDCApplicationARN
711+
- IDCApplicationARN
705712

706713
Conditions:
707714
IsLexV2: !Not [ !Equals [!Ref LexV2BotId, ''] ]
@@ -736,7 +743,7 @@ Resources:
736743
CognitoIdentityPoolName: !Ref CognitoIdentityPoolName
737744
ForceCognitoLogin: !Ref ForceCognitoLogin
738745
LexBotName: !Ref BotName
739-
LexV2BotId:
746+
LexV2BotId:
740747
!If
741748
- NeedsBot
742749
- !GetAtt Bot.Outputs.BotId
@@ -745,7 +752,7 @@ Resources:
745752
!If
746753
- NeedsBot
747754
- !GetAtt Bot.Outputs.BotAlias
748-
- !Ref LexV2BotAliasId
755+
- !Ref LexV2BotAliasId
749756
ShouldEnableLiveChat: !Ref ShouldEnableLiveChat
750757
ShouldEnableUpload: !Ref ShouldEnableUpload
751758
UploadBucket: !Ref UploadBucket
@@ -778,7 +785,7 @@ Resources:
778785
- !GetAtt Bot.Outputs.BotId
779786
- !Ref BotName
780787
BotAlias: !Ref BotAlias
781-
LexV2BotId:
788+
LexV2BotId:
782789
!If
783790
- NeedsBot
784791
- !GetAtt Bot.Outputs.BotId
@@ -787,7 +794,7 @@ Resources:
787794
!If
788795
- NeedsBot
789796
- !GetAtt Bot.Outputs.BotAlias
790-
- !Ref LexV2BotAliasId
797+
- !Ref LexV2BotAliasId
791798
LexV2BotLocaleId: !Ref LexV2BotLocaleId
792799
CognitoIdentityPoolId:
793800
!If
@@ -847,6 +854,7 @@ Resources:
847854
ConnectStartLiveChatIcon: !Ref ConnectStartLiveChatIcon
848855
ConnectEndLiveChatLabel: !Ref ConnectEndLiveChatLabel
849856
ConnectEndLiveChatIcon: !Ref ConnectEndLiveChatIcon
857+
ConnectEndLiveChatUtterance: !Ref ConnectEndLiveChatUtterance
850858
ConnectTranscriptMessageDelayInMsec: !Ref ConnectTranscriptMessageDelayInMsec
851859
MessageTextColor: !Ref MessageTextColor
852860
MessageFont: !Ref MessageFont
@@ -860,7 +868,7 @@ Resources:
860868
AllowStreamingResponses: !Ref AllowStreamingResponses
861869
ShouldEnableUpload: !Ref ShouldEnableUpload
862870
UploadBucket: !Ref UploadBucket
863-
Timestamp: 1723566731
871+
Timestamp: 1724098094
864872

865873
CognitoIdentityPoolConfig:
866874
Type: AWS::CloudFormation::Stack
@@ -874,7 +882,7 @@ Resources:
874882
CodeBuildProjectName: !GetAtt CodeBuildDeploy.Outputs.CodeBuildProject
875883
CognitoUserPool: !GetAtt CognitoIdentityPool.Outputs.CognitoUserPoolId
876884
CognitoUserPoolClient: !GetAtt CognitoIdentityPool.Outputs.CognitoUserPoolClientId
877-
Timestamp: 1723566731
885+
Timestamp: 1724098094
878886

879887
##########################################################################
880888
# Lambda that will validate if user has put in an invalid CSS color/Hex string and fail deployment

0 commit comments

Comments
 (0)