wingbot 3.33.0-alpha.1 → 3.33.2

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.33.0-alpha.1",
3
+ "version": "3.33.2",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -603,19 +603,13 @@ class ConversationTester {
603
603
  } else {
604
604
  const quickReplyRequired = action.match(/^>/);
605
605
  const cleanAction = action.replace(/^>/, '');
606
- let found;
607
606
 
608
607
  // action in quick reply
609
608
  if (action.match(/^>\//)) {
610
609
  await t.quickReply(cleanAction);
611
- found = true;
610
+ } else if (quickReplyRequired) {
611
+ await t.quickReplyText(cleanAction);
612
612
  } else {
613
- found = await t.quickReplyText(cleanAction);
614
- }
615
-
616
- if (!found && quickReplyRequired) {
617
- throw new Error(`Quick reply "${action.replace(/^>/, '')}" was required, but has not been found`);
618
- } else if (!found) {
619
613
  await t.text(action);
620
614
  }
621
615
  }
package/src/Tester.js CHANGED
@@ -452,7 +452,7 @@ class Tester {
452
452
  }
453
453
 
454
454
  /**
455
- * Send quick reply if text exactly matches, otherwise returns false
455
+ * Send quick reply if text exactly matches, otherwise throws exception
456
456
  *
457
457
  * @param {string} text
458
458
  * @returns {Promise<boolean>}
@@ -460,22 +460,38 @@ class Tester {
460
460
  * @memberOf Tester
461
461
  */
462
462
  async quickReplyText (text) {
463
+ let but = 'has not been found.';
463
464
 
464
465
  if (this.responses.length !== 0) {
465
- const search = tokenize(text);
466
+ const normalize = (t) => `${t}`.toLocaleLowerCase().replace(/\s+/g, ' ').trim();
467
+ const normalizedText = normalize(text);
468
+ const search = tokenize(normalizedText);
466
469
  const last = this.responses[this.responses.length - 1];
467
470
  const quickReplys = asserts.getQuickReplies(last);
468
- const res = quickReplys
471
+ let res = quickReplys
469
472
  .filter(({ title = '', payload }) => title && payload && tokenize(title) === search);
470
473
 
471
- if (res[0]) {
474
+ if (res.length > 1) {
475
+ res = res
476
+ .filter(({ title = '' }) => normalize(title) === normalizedText);
477
+ }
478
+
479
+ if (res.length === 1) {
472
480
  const { title, payload } = res[0];
473
481
  await this.processMessage(Request.quickReplyText(this.senderId, title, payload));
474
482
  return true;
475
483
  }
484
+
485
+ if (res.length > 1) {
486
+ but = 'found, but there are multiple occurences.';
487
+ }
488
+
489
+ but += quickReplys.length
490
+ ? ` (found: ${quickReplys.map((q) => q.title).filter((q) => !!q).join(', ')})`
491
+ : ' (no quick replies available)';
476
492
  }
477
493
 
478
- return false;
494
+ throw new Error(`Quick reply "${text}" ${but}`);
479
495
  }
480
496
 
481
497
  /**
@@ -20,7 +20,7 @@ const UNSUBSCRIBE = '_$unsubscribe';
20
20
 
21
21
  function getUpdate (attr, value, currentState = {}) {
22
22
  let param;
23
- let rest = attr;
23
+ let rest = attr && attr.replace(/\u2219/g, '.');
24
24
  let state = currentState;
25
25
  const ret = {};
26
26
  let up = ret;
@@ -53,7 +53,7 @@ function getUpdate (attr, value, currentState = {}) {
53
53
 
54
54
  function getValue (attr, currentState = {}) {
55
55
  let param;
56
- let rest = attr;
56
+ let rest = attr && attr.replace(/\u2219/g, '.');
57
57
  let state = currentState;
58
58
 
59
59
  do {