@@ -98,20 +98,24 @@ export const config: IDashboardConfig = /*return*/ {
98
98
query : ( ) => `where name == 'Transcript'
99
99
| extend conversationId=tostring(customDimensions.userConversationId),
100
100
customerName=tostring(customDimensions.customerName),
101
- userTime=tostring (customDimensions.timestamp)
102
- | project conversationId, customerName, timestamp, userTime, customDimensions
101
+ timestamp=todatetime (customDimensions.timestamp)
102
+ | project conversationId, customerName, timestamp, customDimensions
103
103
| order by timestamp desc
104
- | summarize transcripts_count=count(userTime ),
104
+ | summarize transcripts_count=count(timestamp ),
105
105
transcripts=makelist(customDimensions) by customerName, conversationId
106
106
| project conversationId, customerName, transcripts_count, transcripts` ,
107
107
calculated : ( transcripts ) => {
108
108
const listTranscripts = transcripts . reduce ( ( destArray , currentValue ) => {
109
109
const transcriptsArray = JSON . parse ( currentValue . transcripts ) ;
110
- const lastMessage = transcriptsArray . find ( x => x . from !== 'Bot' ) ;
110
+ if ( ! Array . isArray ( transcriptsArray ) ) {
111
+ return destArray ;
112
+ }
113
+ const lastMessage = transcriptsArray . find ( x => x . from === 'Customer' ) ;
111
114
if ( ! lastMessage ) {
112
115
return destArray ;
113
116
}
114
- const lastSentimentScore = lastMessage . sentimentScore || 0.5 ;
117
+ const lastSentimentScore = parseFloat ( lastMessage . sentimentScore ) || 0.5 ;
118
+ const lastState = parseInt ( transcriptsArray [ 0 ] . state ) ;
115
119
const value = {
116
120
userId : lastMessage . customerId ,
117
121
conversationId : lastMessage . customerConversationId ,
@@ -124,7 +128,8 @@ export const config: IDashboardConfig = /*return*/ {
124
128
lastSentimentScore < 0.4 ? 'sentiment_dissatisfied' :
125
129
lastSentimentScore < 0.6 ? 'sentiment_neutral' :
126
130
lastSentimentScore < 0.8 ? 'sentiment_satisfied' : 'sentiment_very_satisfied' ,
127
- icon : lastMessage . state === 1 ? 'perm_identity' : 'memory' ,
131
+ icon : lastState === 0 ? 'memory' :
132
+ lastState === 2 ? 'perm_identity' : 'more_horiz' ,
128
133
} ;
129
134
destArray . push ( value ) ;
130
135
return destArray ;
@@ -156,10 +161,20 @@ export const config: IDashboardConfig = /*return*/ {
156
161
const avgTimeWaiting = times . reduce ( ( a , c ) => a + c , 0 ) / times . length ;
157
162
const maxTimeWaiting = Math . max ( ...times ) ;
158
163
const minTimeWaiting = Math . min ( ...times ) ;
164
+ const timeFormat = ( secs ) => {
165
+ const time = new Date ( secs * 1000 ) ;
166
+ let t = time . getSeconds ( ) + 's' ;
167
+ if ( time . getHours ( ) > 0 && time . getMinutes ( ) > 0 ) {
168
+ t = time . getHours ( ) + 'h ' + time . getMinutes ( ) + 'm' ;
169
+ } else if ( time . getMinutes ( ) > 0 ) {
170
+ t = time . getMinutes ( ) + 'm' ;
171
+ }
172
+ return t ;
173
+ } ;
159
174
return {
160
- 'transcriptsAverageTimeWaiting-value' : avgTimeWaiting . toFixed ( 1 ) ,
161
- 'transcriptsLongestTimeWaiting-value' : maxTimeWaiting . toFixed ( 1 ) ,
162
- 'transcriptsShortestTimeWaiting-value' : minTimeWaiting . toFixed ( 1 ) ,
175
+ 'transcriptsAverageTimeWaiting-value' : isFinite ( avgTimeWaiting ) ? timeFormat ( avgTimeWaiting ) : '-' ,
176
+ 'transcriptsLongestTimeWaiting-value' : isFinite ( avgTimeWaiting ) ? timeFormat ( maxTimeWaiting ) : '-' ,
177
+ 'transcriptsShortestTimeWaiting-value' : isFinite ( avgTimeWaiting ) ? timeFormat ( minTimeWaiting ) : '-' ,
163
178
} ;
164
179
}
165
180
} ,
@@ -226,15 +241,23 @@ export const config: IDashboardConfig = /*return*/ {
226
241
} ,
227
242
228
243
customerTranscripts : {
229
- query : ( ) => `where name == 'Transcript'
230
- | summarize
231
- maxState=max(toint(customDimensions.state))
232
- by customerConversationId=tostring(customDimensions.userConversationId),
233
- customerName=tostring(customDimensions.customerName)` ,
244
+ query : ( ) => `where name == 'Transcript'
245
+ | extend customerId=tostring(customDimensions.customerId)
246
+ | extend state=toint(customDimensions.state)
247
+ | extend timestamp=todatetime(customDimensions.timestamp)
248
+ | project customerId, timestamp, state
249
+ | order by timestamp desc
250
+ | summarize transcripts_count=count(customerId), timestamps=makelist(timestamp) by customerId, state
251
+ | project customerId, state, transcripts_count, timestamp=timestamps[0]
252
+ | summarize count(customerId),
253
+ totals=makelist(transcripts_count),
254
+ states=makelist(state),
255
+ timestamps=makelist(timestamp) by customerId
256
+ | project customerId, state=toint(states[0]), transcripts_count=toint(totals[0]), timestamp=timestamps[0]` ,
234
257
calculated : ( customerTranscripts ) => {
235
- const bot = customerTranscripts . filter ( ( e ) => e . maxState === 0 ) ;
236
- const waiting = customerTranscripts . filter ( ( e ) => e . maxState === 1 ) ;
237
- const agent = customerTranscripts . filter ( ( e ) => e . maxState === 2 ) ;
258
+ const bot = customerTranscripts . filter ( ( customer ) => customer . state === 0 ) ;
259
+ const waiting = customerTranscripts . filter ( ( customer ) => customer . state === 1 ) ;
260
+ const agent = customerTranscripts . filter ( ( customer ) => customer . state === 2 ) ;
238
261
return {
239
262
'customerTotal-value' : customerTranscripts . length ,
240
263
'customerBot-value' : bot . length ,
0 commit comments