wingbot 3.46.3 → 3.47.0

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.3",
3
+ "version": "3.47.0",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -35,6 +35,7 @@ const DEFAULT_TEXT_THRESHOLD = 0.8;
35
35
  * @prop {string} text
36
36
  * @prop {string} action
37
37
  * @prop {string} intent
38
+ * @prop {number} [rowNum]
38
39
  */
39
40
 
40
41
  /**
@@ -562,10 +563,37 @@ class ConversationTester {
562
563
  score: 0, intent: { intent: '-', score: 0 }, aboveConfidence: false, meta: null, action: null
563
564
  }] = actions;
564
565
 
565
- const report = (error = '', ok = false) => ({
566
- ok,
567
- o: `${textCase.text.padEnd(longestText, ' ')}\t${(winner.intent ? winner.intent.score : 0).toFixed(2)}\t${winner.intent ? winner.intent.intent : '-'} | ${error}`
568
- });
566
+ // textCase.rowNum?
567
+
568
+ const report = (error, ok = false) => {
569
+ let o = [
570
+ textCase.text.padEnd(longestText, ' '),
571
+ (winner.intent ? winner.intent.score : 0).toFixed(2),
572
+ winner.intent ? winner.intent.intent : '-'
573
+ ].join('\t');
574
+
575
+ if (ok || !error) {
576
+ if (error) {
577
+ o += ` | ${error}`;
578
+ }
579
+ return { ok, o };
580
+ }
581
+
582
+ let err = error;
583
+
584
+ const prefix = typeof textCase.rowNum === 'number'
585
+ ? ` > FAILED on row ${textCase.rowNum}: `.padEnd(23, ' ')
586
+ : ' > FAILED: ';
587
+
588
+ if (Array.isArray(err)) {
589
+ const pad = ''.padEnd(prefix.length, ' ');
590
+ err = err.join(`\n${pad}`);
591
+ }
592
+
593
+ o += `\n${prefix}${err}`;
594
+
595
+ return { ok, o };
596
+ };
569
597
 
570
598
  if (actions.length === 0) {
571
599
  return report('no NLP result');
@@ -576,25 +604,40 @@ class ConversationTester {
576
604
  }
577
605
 
578
606
  if (textCase.intent && winner.intent.intent !== textCase.intent) {
579
- return report(`expected intent "${textCase.intent}"`);
607
+ return report([
608
+ 'intent mismatch',
609
+ `✓ expected: ${textCase.intent}`,
610
+ `✗ actual: ${winner.intent.intent || '-'}`
611
+ ]);
580
612
  }
581
613
 
582
614
  if (textCase.appId) {
583
-
584
615
  if (!winner.meta || `${winner.meta.targetAppId}` !== `${textCase.appId}`) {
585
- return report(`expected handover to "${textCase.appId}" - actual "${(winner.meta && winner.meta.targetAppId) || `action: ${winner.action || '*'}`}"`);
616
+ return report([
617
+ 'target appId mismatch',
618
+ `✓ expected: ${textCase.appId}`,
619
+ `✗ actual: ${(winner.meta && winner.meta.targetAppId) || `action[ ${winner.action || '*'} ]`}`
620
+ ]);
586
621
  }
587
622
 
588
623
  if (textCase.action && !actionMatches(`${winner.meta.targetAction}`, `${textCase.action}`)) {
589
- return report(`expected action "${textCase.action}" - actual "${winner.meta.targetAction || '-'}"`);
624
+ return report([
625
+ 'target action mismatch',
626
+ `✓ expected: ${textCase.action}`,
627
+ `✗ actual: ${winner.meta.targetAction || '-'}`
628
+ ]);
590
629
  }
591
630
 
592
631
  } else if (textCase.action && !actionMatches(`${winner.action}`, `${textCase.action}`)) {
593
- return report(`expected action "${textCase.action}" - actual "${winner.action || '-'}"`);
632
+ return report([
633
+ 'action mismatch',
634
+ `✓ expected: ${textCase.action}`,
635
+ `✗ actual: ${winner.action || '-'}`
636
+ ]);
594
637
  }
595
638
 
596
639
  if (!textCase.action && !textCase.appId && !textCase.intent) {
597
- return report(`${textCase.action}`, true);
640
+ return report(winner.action, true);
598
641
  }
599
642
 
600
643
  return { ok: true, o: null };
package/src/Processor.js CHANGED
@@ -63,6 +63,7 @@ const { mergeState, isUserInteraction } = require('./utils/stateVariables');
63
63
  * @prop {ResponseFlag|null} flag
64
64
  * @prop {boolean} nonInteractive
65
65
  * @prop {string[]} responseTexts
66
+ * @prop {boolean} doNotTrack
66
67
  */
67
68
 
68
69
  /**
@@ -421,12 +422,7 @@ class Processor extends EventEmitter {
421
422
  * @returns {Promise}
422
423
  */
423
424
  _emitInteractionEvent (req, res, messageSender, state, data) {
424
- const shouldNotTrack = data._initialEventShouldNotBeTracked === true;
425
-
426
- if (shouldNotTrack) {
427
- return Promise.resolve();
428
- }
429
-
425
+ const doNotTrack = data._initialEventShouldNotBeTracked === true;
430
426
  const { _lastAction: lastAction = null } = req.state;
431
427
  const actions = messageSender.visitedInteractions;
432
428
  const skill = typeof res.newState._trackAsSkill === 'undefined'
@@ -435,6 +431,7 @@ class Processor extends EventEmitter {
435
431
  const { events = [] } = messageSender.tracking;
436
432
 
437
433
  const event = {
434
+ doNotTrack,
438
435
  responseTexts: messageSender.responseTexts,
439
436
  req,
440
437
  actions,
@@ -445,7 +442,7 @@ class Processor extends EventEmitter {
445
442
  tracking: messageSender.tracking,
446
443
  events,
447
444
  flag: res.senderMeta.flag,
448
- nonInteractive: !isUserInteraction(req)
445
+ nonInteractive: !isUserInteraction(req) || doNotTrack
449
446
  };
450
447
 
451
448
  return Promise.allSettled([
@@ -610,10 +607,10 @@ class Processor extends EventEmitter {
610
607
 
611
608
  const interactive = isUserInteraction(req);
612
609
 
613
- if ((isUserInteraction(req)
614
- && (sessionTs + this.options.sessionDuration) < Date.now())
615
- || !sessionId) {
610
+ const sessionExpired = interactive
611
+ && (sessionTs + this.options.sessionDuration) < Date.now();
616
612
 
613
+ if (sessionExpired || !sessionId) {
617
614
  sessionStart = timestamp;
618
615
  sessionTs = timestamp;
619
616
  sessionId = Processor._createSessionId(req.pageId, req.senderId, timestamp);
@@ -239,7 +239,8 @@ function onInteractionHandler (
239
239
  events,
240
240
  flag,
241
241
  nonInteractive,
242
- responseTexts
242
+ responseTexts,
243
+ doNotTrack = false
243
244
  }) {
244
245
  if (!enabled) {
245
246
  return;
@@ -321,7 +322,7 @@ function onInteractionHandler (
321
322
  score = 0
322
323
  } = {}] = req.intents;
323
324
 
324
- const text = req.isConfidentInput()
325
+ const text = req.isConfidentInput() || doNotTrack
325
326
  ? '*****'
326
327
  : anonymize(
327
328
  replaceDiacritics(req.text()).replace(/\s+/g, ' ').toLowerCase().trim()
@@ -396,47 +397,49 @@ function onInteractionHandler (
396
397
  const notHandled = actions.some((a) => a.match(/\*$/)) && !req.isQuickReply();
397
398
  const value = notHandled ? 1 : 0;
398
399
 
399
- trackEvents.push({
400
- type: TrackingType.PAGE_VIEW,
401
- category: asCategory(TrackingCategory.PAGE_VIEW_FIRST),
402
- action,
403
- label: (isText || isQuickReply ? text : null),
404
- value,
405
- allActions,
406
- nonInteractive,
407
- lastAction,
408
- // @ts-ignore
409
- prevAction: lastAction,
410
- skill: useSkill,
411
- isGoto: false,
412
- withUser,
413
- ...langsExtension,
414
- ...(hasExtendedEvents ? {} : actionMeta)
415
- });
416
-
417
- let prevAction = action;
418
-
419
- trackEvents.push(
420
- ...otherActions.map((a) => {
421
- const r = {
422
- type: TrackingType.PAGE_VIEW,
423
- category: asCategory(TrackingCategory.PAGE_VIEW_SUBSEQUENT),
424
- action: a,
425
- value: 0,
426
- allActions,
427
- nonInteractive: false,
428
- lastAction,
429
- prevAction,
430
- skill: useSkill,
431
- isGoto: true,
432
- withUser,
433
- ...langsExtension
434
- };
400
+ if (!doNotTrack) {
401
+ trackEvents.push({
402
+ type: TrackingType.PAGE_VIEW,
403
+ category: asCategory(TrackingCategory.PAGE_VIEW_FIRST),
404
+ action,
405
+ label: (isText || isQuickReply ? text : null),
406
+ value,
407
+ allActions,
408
+ nonInteractive,
409
+ lastAction,
410
+ // @ts-ignore
411
+ prevAction: lastAction,
412
+ skill: useSkill,
413
+ isGoto: false,
414
+ withUser,
415
+ ...langsExtension,
416
+ ...(hasExtendedEvents ? {} : actionMeta)
417
+ });
435
418
 
436
- prevAction = a;
437
- return r;
438
- })
439
- );
419
+ let prevAction = action;
420
+
421
+ trackEvents.push(
422
+ ...otherActions.map((a) => {
423
+ const r = {
424
+ type: TrackingType.PAGE_VIEW,
425
+ category: asCategory(TrackingCategory.PAGE_VIEW_SUBSEQUENT),
426
+ action: a,
427
+ value: 0,
428
+ allActions,
429
+ nonInteractive: false,
430
+ lastAction,
431
+ prevAction,
432
+ skill: useSkill,
433
+ isGoto: true,
434
+ withUser,
435
+ ...langsExtension
436
+ };
437
+
438
+ prevAction = a;
439
+ return r;
440
+ })
441
+ );
442
+ }
440
443
 
441
444
  trackEvents.push(
442
445
  ...events.map(({
@@ -453,7 +456,6 @@ function onInteractionHandler (
453
456
  );
454
457
 
455
458
  if (!nonInteractive) {
456
-
457
459
  if (req.isText()) {
458
460
  trackEvents.push({
459
461
  type: TrackingType.TRAINING,