wingbot 3.46.0-alpha.5 → 3.46.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.46.0-alpha.5",
3
+ "version": "3.46.0-alpha.7",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -62,12 +62,12 @@ const TrackingCategory = { // max length 3
62
62
 
63
63
  // TRAINING: 'train'
64
64
  INTENT_DETECTION: 'int',
65
- HANDOVER_OCCURRED: 'hum',
66
65
  DISAMBIGUATION_SELECTED: 'dis',
67
66
  DISAMBIGUATION_OFFERED: 'dio',
68
67
 
69
68
  // REPORT: 'report'
70
- REPORT_FEEDBACK: 'fdb'
69
+ REPORT_FEEDBACK: 'fdb',
70
+ HANDOVER_OCCURRED: 'hum'
71
71
  };
72
72
 
73
73
  /**
@@ -94,12 +94,12 @@ const CATEGORY_LABELS = {
94
94
 
95
95
  // TRAINING: 'train'
96
96
  [TrackingCategory.INTENT_DETECTION]: 'Intent: Detection',
97
- [TrackingCategory.HANDOVER_OCCURRED]: 'Bot: Handover out',
98
97
  [TrackingCategory.DISAMBIGUATION_SELECTED]: 'Disambiguation: selected',
99
98
  [TrackingCategory.DISAMBIGUATION_OFFERED]: 'Disambiguation: offered',
100
99
 
101
100
  // REPORT: 'report'
102
- [TrackingCategory.REPORT_FEEDBACK]: 'User: Feedback'
101
+ [TrackingCategory.REPORT_FEEDBACK]: 'User: Feedback',
102
+ [TrackingCategory.HANDOVER_OCCURRED]: 'Bot: Handover out'
103
103
  };
104
104
 
105
105
  module.exports = {
@@ -37,6 +37,7 @@ const {
37
37
 
38
38
  /**
39
39
  * @typedef {object} ConversationEventExtension
40
+ * @prop {string} [lastAction]
40
41
  * @prop {string} [skill]
41
42
  * @prop {string} [text]
42
43
  * @prop {string} [expected]
@@ -70,7 +71,23 @@ const {
70
71
  */
71
72
 
72
73
  /**
73
- * @typedef {ConversationEvent | Event} TrackingEvent
74
+ * @typedef {object} PageViewEventExtension
75
+ * @prop {string} [lastAction]
76
+ * @prop {string} [prevAction]
77
+ * @prop {string} [skill]
78
+ * @prop {number} sessionDuration
79
+ * @prop {string[]|string} allActions
80
+ * @prop {boolean} nonInteractive
81
+ * @prop {boolean} isGoto
82
+ * @prop {boolean} withUser
83
+ * @prop {string} [snapshot]
84
+ * @prop {string} [botId]
85
+ *
86
+ * @typedef {Event & PageViewEventExtension} PageViewEvent
87
+ */
88
+
89
+ /**
90
+ * @typedef {ConversationEvent | Event | PageViewEvent} TrackingEvent
74
91
  */
75
92
 
76
93
  /**
@@ -208,7 +225,7 @@ function onInteractionHandler (
208
225
  const asArray = (data = []) => (supportsArrays ? data : data.join(','));
209
226
  const asCategory = (cat) => (useDescriptiveCategories && CATEGORY_LABELS[cat]) || cat;
210
227
  const noneAction = useExtendedScalars ? null : '(none)';
211
- const noneValue = useExtendedScalars ? -1 : 0;
228
+ const noneValue = useExtendedScalars ? null : 0;
212
229
 
213
230
  /**
214
231
  * @param {InteractionEvent} params
@@ -243,8 +260,31 @@ function onInteractionHandler (
243
260
  lang
244
261
  } = req.state;
245
262
 
263
+ const trackEvents = [];
264
+
246
265
  const [action = noneAction, ...otherActions] = actions;
247
266
 
267
+ const feedbackEvent = events.find((e) => e.type === TrackingType.REPORT
268
+ && e.category === TrackingCategory.REPORT_FEEDBACK);
269
+ const feedback = feedbackEvent
270
+ ? feedbackEvent.value
271
+ : noneValue;
272
+ let didHandover = flag === ResponseFlag.HANDOVER;
273
+ const hasHandoverEvent = events
274
+ .some((e) => e.category === TrackingCategory.HANDOVER_OCCURRED);
275
+
276
+ if (didHandover && !hasHandoverEvent) {
277
+ trackEvents.push({
278
+ type: TrackingType.REPORT,
279
+ category: asCategory(TrackingCategory.HANDOVER_OCCURRED),
280
+ action: null,
281
+ label: null,
282
+ value: noneValue
283
+ });
284
+ } else if (hasHandoverEvent) {
285
+ didHandover = true;
286
+ }
287
+
248
288
  let sessionPromise;
249
289
  if (createSession) {
250
290
  const metadata = {
@@ -252,7 +292,9 @@ function onInteractionHandler (
252
292
  lang,
253
293
  action,
254
294
  snapshot,
255
- botId
295
+ botId,
296
+ didHandover,
297
+ feedback
256
298
  };
257
299
 
258
300
  sessionPromise = analyticsStorage.createUserSession(
@@ -281,6 +323,7 @@ function onInteractionHandler (
281
323
  : anonymize(
282
324
  replaceDiacritics(req.text()).replace(/\s+/g, ' ').toLowerCase().trim()
283
325
  );
326
+ const useSkill = (skill && webalize(skill)) || noneAction;
284
327
 
285
328
  let winnerAction = '';
286
329
  let winnerScore = 0;
@@ -301,14 +344,6 @@ function onInteractionHandler (
301
344
  }
302
345
 
303
346
  const expected = req.expected() ? req.expected().action : '';
304
-
305
- const feedbackEvent = events.find((e) => e.type === TrackingType.REPORT
306
- && e.category === TrackingCategory.REPORT_FEEDBACK);
307
- const feedback = feedbackEvent
308
- ? feedbackEvent.value
309
- : noneValue;
310
- const didHandover = flag === ResponseFlag.HANDOVER;
311
-
312
347
  const user = userExtractor(req.state);
313
348
 
314
349
  const isContextUpdate = req.isSetContext();
@@ -322,12 +357,12 @@ function onInteractionHandler (
322
357
  const allActions = asArray(actions);
323
358
  const requestAction = req.action();
324
359
 
325
- const trackEvents = [];
326
-
327
360
  const langsExtension = hasExtendedEvents
328
361
  ? { lang }
329
362
  : { cd1: lang };
330
363
 
364
+ const withUser = user !== null && !!user.id;
365
+
331
366
  const actionMeta = {
332
367
  requestAction: req.action() || noneAction,
333
368
  expected,
@@ -340,11 +375,11 @@ function onInteractionHandler (
340
375
  isText,
341
376
  isPostback,
342
377
  didHandover,
343
- withUser: user !== null && !!user.id,
378
+ withUser,
344
379
  sessionStart,
345
380
  sessionDuration: sessionTs - sessionStart,
346
381
  feedback,
347
- skill: (skill && webalize(skill)) || noneAction,
382
+ skill: useSkill,
348
383
  snapshot,
349
384
  botId,
350
385
  winnerAction,
@@ -371,12 +406,16 @@ function onInteractionHandler (
371
406
  allActions,
372
407
  nonInteractive,
373
408
  lastAction,
409
+ // @ts-ignore
374
410
  prevAction: lastAction,
375
- skill,
376
- lang,
377
- cd1: req.state.lang,
411
+ skill: useSkill,
378
412
  isGoto: false,
379
413
  sessionStart,
414
+ sessionDuration: timestamp - sessionStart,
415
+ withUser,
416
+ snapshot,
417
+ botId,
418
+ ...langsExtension,
380
419
  ...(hasExtendedEvents ? {} : actionMeta)
381
420
  });
382
421
 
@@ -393,9 +432,12 @@ function onInteractionHandler (
393
432
  nonInteractive: false,
394
433
  lastAction,
395
434
  prevAction,
396
- skill,
435
+ skill: useSkill,
397
436
  isGoto: true,
398
437
  sessionStart,
438
+ sessionDuration: timestamp - sessionStart,
439
+ snapshot,
440
+ botId,
399
441
  ...langsExtension
400
442
  };
401
443
 
@@ -410,7 +452,7 @@ function onInteractionHandler (
410
452
  }) => ({
411
453
  lastAction,
412
454
  type,
413
- category,
455
+ category: asCategory(category),
414
456
  action: eventAction,
415
457
  label,
416
458
  value: eVal,
@@ -474,7 +516,6 @@ function onInteractionHandler (
474
516
  trackEvents.push({
475
517
  ...(analyticsStorage.hasExtendedEvents ? actionMeta : {}),
476
518
  type: TrackingType.CONVERSATION_EVENT,
477
- // @ts-ignore
478
519
  lastAction,
479
520
  category: asCategory(actionCategory),
480
521
  action,