Skip to content

Commit 71837f5

Browse files
committed
Support redacting transcript delivered to agents when a user connects to live chat.
1 parent 94e8e40 commit 71837f5

File tree

7 files changed

+40
-8
lines changed

7 files changed

+40
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ const lexV2BotLocaleVoices = {
149149
'CONNECT_END_LIVE_CHAT_ICON',
150150
'CONNECT_END_LIVE_CHAT_UTTERANCE',
151151
'CONNECT_TRANSCRIPT_MESSAGE_DELAY_IN_MSEC',
152+
'CONNECT_TRANSCRIPT_REDACT_REGEX',
152153
'APP_DOMAIN_NAME',
153154
'UI_TOOLBAR_TITLE',
154155
'UI_TOOLBAR_LOGO',

config/base.env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
liveChatTerms: process.env.CONNECT_LIVE_CHAT_TERMS,
2626
endLiveChatUtterance: process.env.CONNECT_END_LIVE_CHAT_UTTERANCE,
2727
transcriptMessageDelayInMsec: process.env.CONNECT_TRANSCRIPT_MESSAGE_DELAY_IN_MSEC,
28+
transcriptRedactRegex: process.env.CONNECT_TRANSCRIPT_REDACT_REGEX,
2829
},
2930
lex: {
3031
v2BotId: process.env.V2_BOT_ID,

config/env.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export CONNECT_END_LIVE_CHAT_LABEL ?= $()
3838
export CONNECT_END_LIVE_CHAT_ICON ?= $()
3939
export CONNECT_END_LIVE_CHAT_UTTERANCE ?= $()
4040
export CONNECT_TRANSCRIPT_MESSAGE_DELAY_IN_MSEC ?= $()
41+
export CONNECT_TRANSCRIPT_REDACT_REGEX ?= $()
4142
export BOT_INITIAL_TEXT ?= $()
4243
export BOT_INITIAL_SPEECH ?= $()
4344
export BOT_INITIAL_UTTERANCE ?= $()

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,37 @@ export default {
5959
return v;
6060
},
6161
liveChatTextTranscriptArray: state => () => {
62+
// Support redacting messages delivered to agent based on config.connect.transcriptRedactRegex.
63+
// Use case is to support redacting post chat survey responses from being seen by agents if user
64+
// reconnects with an agent.
6265
const messageTextArray = [];
63-
var text = "";
66+
var text = "";
67+
let shouldRedactResponse = false; // indicates if the current message should be redacted
68+
const regex = new RegExp(`${state.config.connect.transcriptRedactRegex}`, "g");
6469
state.messages.forEach((message) => {
6570
var nextMessage = message.date.toLocaleTimeString() + ' ' + (message.type === 'bot' ? 'Bot' : 'Human') + ': ' + message.text + '\n';
71+
if (shouldRedactResponse) {
72+
nextMessage = message.date.toLocaleTimeString() + ' ' + (message.type === 'bot' ? 'Bot' : 'Human') + ': ' + '###' + '\n';
73+
}
6674
if((text + nextMessage).length > 400) {
6775
messageTextArray.push(text);
6876
//this is over 1k chars by itself, so we must break it up.
69-
var subMessageArray = nextMessage.match(/(.|[\r\n]){1,400}/g);
77+
var subMessageArray = nextMessage.match(/(.|[\r\n]){1,400}/g);
7078
subMessageArray.forEach((subMsg) => {
7179
messageTextArray.push(subMsg);
7280
});
7381
text = "";
82+
shouldRedactResponse= regex.test(nextMessage);
7483
nextMessage = "";
75-
}
76-
text = text + nextMessage;
84+
} else {
85+
shouldRedactResponse= regex.test(nextMessage);
86+
}
87+
text = text + nextMessage;
7788
});
7889
messageTextArray.push(text);
7990
return messageTextArray;
8091
},
81-
liveChatTranscriptFile: state => () => {
92+
liveChatTranscriptFile: state => () => {
8293
var text = 'Bot Transcript: \n';
8394
state.messages.forEach((message) => text = text + message.date.toLocaleTimeString() + ' ' + (message.type === 'bot' ? 'Bot' : 'Human') + ': ' + message.text + '\n');
8495
var blob = new Blob([text], { type: 'text/plain'});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"chatEndedMessage": "",
1212
"attachChatTranscript": "",
1313
"endLiveChatUtterance": "",
14-
"transcriptMessageDelayInMsec": ""
14+
"transcriptMessageDelayInMsec": "",
15+
"transcriptRedactRegex": ""
1516
}
1617
}

templates/codebuild-deploy.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ Parameters:
242242
Delay to insert between each transcript message send to Connect in msec.
243243
Default: 150
244244

245+
ConnectTranscriptRedactRegex:
246+
Type: String
247+
Description: >
248+
Optional regex used to redact entire lines in transcript sent to agent
249+
Default: ''
250+
245251
LexV2BotId:
246252
Description: >
247253
Bot ID (not bot name) of an existing Lex V2 Bot to be used by the web ui. NOTE: You must
@@ -849,6 +855,8 @@ Resources:
849855
Value: !Ref ConnectEndLiveChatUtterance
850856
- Name: CONNECT_TRANSCRIPT_MESSAGE_DELAY_IN_MSEC
851857
Value: !Ref ConnectTranscriptMessageDelayInMsec
858+
- Name: CONNECT_TRANSCRIPT_REDACT_REGEX
859+
Value: !Ref ConnectTranscriptRedactRegex
852860
- Name: APP_USER_POOL_CLIENT_ID
853861
Value: !Ref CognitoAppUserPoolClientId
854862
- Name: APP_USER_POOL_NAME
@@ -997,6 +1005,7 @@ Resources:
9971005
ConnectEndLiveChatIcon: !Ref ConnectEndLiveChatIcon
9981006
ConnectEndLiveChatUtterance: !Ref ConnectEndLiveChatUtterance
9991007
ConnectTranscriptMessageDelayInMsec: !Ref ConnectTranscriptMessageDelayInMsec
1008+
ConnectTranscriptRedactRegex: !Ref ConnectTranscriptRedactRegex
10001009
WebAppBucket: !Ref WebAppBucket
10011010
LexV2BotId: !Ref LexV2BotId
10021011
LexV2BotAliasId: !Ref LexV2BotAliasId

templates/master.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,12 @@ Parameters:
492492
Optional utterance to send to bot after ending a live chat session
493493
Default: ''
494494

495+
ConnectTranscriptRedactRegex:
496+
Type: String
497+
Description: >
498+
Optional regex used to redact entire lines in transcript sent to agent
499+
Default: ''
500+
495501
## CSS Configuration Options
496502
MessageTextColor:
497503
Type: String
@@ -694,6 +700,7 @@ Metadata:
694700
- ConnectEndLiveChatIcon
695701
- ConnectEndLiveChatUtterance
696702
- ConnectTranscriptMessageDelayInMsec
703+
- ConnectTranscriptRedactRegex
697704
- Label:
698705
default: CSS Customization Parameters
699706
Parameters:
@@ -856,6 +863,7 @@ Resources:
856863
ConnectEndLiveChatIcon: !Ref ConnectEndLiveChatIcon
857864
ConnectEndLiveChatUtterance: !Ref ConnectEndLiveChatUtterance
858865
ConnectTranscriptMessageDelayInMsec: !Ref ConnectTranscriptMessageDelayInMsec
866+
ConnectTranscriptRedactRegex: !Ref ConnectTranscriptRedactRegex
859867
MessageTextColor: !Ref MessageTextColor
860868
MessageFont: !Ref MessageFont
861869
ChatBackgroundColor: !Ref ChatBackgroundColor
@@ -868,7 +876,7 @@ Resources:
868876
AllowStreamingResponses: !Ref AllowStreamingResponses
869877
ShouldEnableUpload: !Ref ShouldEnableUpload
870878
UploadBucket: !Ref UploadBucket
871-
Timestamp: 1724098094
879+
Timestamp: 1730925847
872880

873881
CognitoIdentityPoolConfig:
874882
Type: AWS::CloudFormation::Stack
@@ -882,7 +890,7 @@ Resources:
882890
CodeBuildProjectName: !GetAtt CodeBuildDeploy.Outputs.CodeBuildProject
883891
CognitoUserPool: !GetAtt CognitoIdentityPool.Outputs.CognitoUserPoolId
884892
CognitoUserPoolClient: !GetAtt CognitoIdentityPool.Outputs.CognitoUserPoolClientId
885-
Timestamp: 1724098094
893+
Timestamp: 1730925847
886894

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

0 commit comments

Comments
 (0)