@@ -64,11 +64,15 @@ export default {
64
64
// reconnects with an agent.
65
65
const messageTextArray = [ ] ;
66
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" ) ;
67
+ let redactionEnabled = false ;
68
+ if ( state . config . connect . transcriptRedactRegex && state . config . connect . transcriptRedactRegex . length > 0 ) {
69
+ redactionEnabled = true ;
70
+ }
71
+ let shouldRedactNextMessage = false ; // indicates if the next message to append should be redacted
72
+ const regex = redactionEnabled ? new RegExp ( `${ state . config . connect . transcriptRedactRegex } ` , "g" ) : undefined ;
69
73
state . messages . forEach ( ( message ) => {
70
74
var nextMessage = message . date . toLocaleTimeString ( ) + ' ' + ( message . type === 'bot' ? 'Bot' : 'Human' ) + ': ' + message . text + '\n' ;
71
- if ( shouldRedactResponse ) {
75
+ if ( redactionEnabled && shouldRedactNextMessage ) {
72
76
nextMessage = message . date . toLocaleTimeString ( ) + ' ' + ( message . type === 'bot' ? 'Bot' : 'Human' ) + ': ' + '###' + '\n' ;
73
77
}
74
78
if ( ( text + nextMessage ) . length > 400 ) {
@@ -79,10 +83,15 @@ export default {
79
83
messageTextArray . push ( subMsg ) ;
80
84
} ) ;
81
85
text = "" ;
82
- shouldRedactResponse = regex . test ( nextMessage ) ;
86
+ if ( redactionEnabled && regex ) {
87
+ shouldRedactNextMessage = regex . test ( nextMessage ) ;
88
+ }
83
89
nextMessage = "" ;
84
90
} else {
85
- shouldRedactResponse = regex . test ( nextMessage ) ;
91
+ if ( redactionEnabled && regex ) {
92
+ // if we are redacting, check if the next message should be redacted
93
+ shouldRedactNextMessage = regex . test ( nextMessage ) ;
94
+ }
86
95
}
87
96
text = text + nextMessage ;
88
97
} ) ;
0 commit comments