wingbot 3.46.0-alpha.5 → 3.46.0-alpha.6

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.6",
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
@@ -281,6 +298,7 @@ function onInteractionHandler (
281
298
  : anonymize(
282
299
  replaceDiacritics(req.text()).replace(/\s+/g, ' ').toLowerCase().trim()
283
300
  );
301
+ const useSkill = (skill && webalize(skill)) || noneAction;
284
302
 
285
303
  let winnerAction = '';
286
304
  let winnerScore = 0;
@@ -300,6 +318,8 @@ function onInteractionHandler (
300
318
  winnerTaken = action === winnerAction;
301
319
  }
302
320
 
321
+ const trackEvents = [];
322
+
303
323
  const expected = req.expected() ? req.expected().action : '';
304
324
 
305
325
  const feedbackEvent = events.find((e) => e.type === TrackingType.REPORT
@@ -307,7 +327,21 @@ function onInteractionHandler (
307
327
  const feedback = feedbackEvent
308
328
  ? feedbackEvent.value
309
329
  : noneValue;
310
- const didHandover = flag === ResponseFlag.HANDOVER;
330
+ let didHandover = flag === ResponseFlag.HANDOVER;
331
+ const hasHandoverEvent = events
332
+ .some((e) => e.category === TrackingCategory.HANDOVER_OCCURRED);
333
+
334
+ if (didHandover && !hasHandoverEvent) {
335
+ trackEvents.push({
336
+ type: TrackingType.REPORT,
337
+ category: asCategory(TrackingCategory.HANDOVER_OCCURRED),
338
+ action: null,
339
+ label: null,
340
+ value: noneValue
341
+ });
342
+ } else if (hasHandoverEvent) {
343
+ didHandover = true;
344
+ }
311
345
 
312
346
  const user = userExtractor(req.state);
313
347
 
@@ -322,12 +356,12 @@ function onInteractionHandler (
322
356
  const allActions = asArray(actions);
323
357
  const requestAction = req.action();
324
358
 
325
- const trackEvents = [];
326
-
327
359
  const langsExtension = hasExtendedEvents
328
360
  ? { lang }
329
361
  : { cd1: lang };
330
362
 
363
+ const withUser = user !== null && !!user.id;
364
+
331
365
  const actionMeta = {
332
366
  requestAction: req.action() || noneAction,
333
367
  expected,
@@ -340,11 +374,11 @@ function onInteractionHandler (
340
374
  isText,
341
375
  isPostback,
342
376
  didHandover,
343
- withUser: user !== null && !!user.id,
377
+ withUser,
344
378
  sessionStart,
345
379
  sessionDuration: sessionTs - sessionStart,
346
380
  feedback,
347
- skill: (skill && webalize(skill)) || noneAction,
381
+ skill: useSkill,
348
382
  snapshot,
349
383
  botId,
350
384
  winnerAction,
@@ -371,12 +405,16 @@ function onInteractionHandler (
371
405
  allActions,
372
406
  nonInteractive,
373
407
  lastAction,
408
+ // @ts-ignore
374
409
  prevAction: lastAction,
375
- skill,
376
- lang,
377
- cd1: req.state.lang,
410
+ skill: useSkill,
378
411
  isGoto: false,
379
412
  sessionStart,
413
+ sessionDuration: timestamp - sessionStart,
414
+ withUser,
415
+ snapshot,
416
+ botId,
417
+ ...langsExtension,
380
418
  ...(hasExtendedEvents ? {} : actionMeta)
381
419
  });
382
420
 
@@ -393,9 +431,12 @@ function onInteractionHandler (
393
431
  nonInteractive: false,
394
432
  lastAction,
395
433
  prevAction,
396
- skill,
434
+ skill: useSkill,
397
435
  isGoto: true,
398
436
  sessionStart,
437
+ sessionDuration: timestamp - sessionStart,
438
+ snapshot,
439
+ botId,
399
440
  ...langsExtension
400
441
  };
401
442
 
@@ -410,7 +451,7 @@ function onInteractionHandler (
410
451
  }) => ({
411
452
  lastAction,
412
453
  type,
413
- category,
454
+ category: asCategory(category),
414
455
  action: eventAction,
415
456
  label,
416
457
  value: eVal,
@@ -474,7 +515,6 @@ function onInteractionHandler (
474
515
  trackEvents.push({
475
516
  ...(analyticsStorage.hasExtendedEvents ? actionMeta : {}),
476
517
  type: TrackingType.CONVERSATION_EVENT,
477
- // @ts-ignore
478
518
  lastAction,
479
519
  category: asCategory(actionCategory),
480
520
  action,