wingbot 3.33.0 → 3.33.1
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 +1 -1
- package/src/ConversationTester.js +2 -8
- package/src/Tester.js +20 -5
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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,37 @@ class Tester {
|
|
|
460
460
|
* @memberOf Tester
|
|
461
461
|
*/
|
|
462
462
|
async quickReplyText (text) {
|
|
463
|
+
let found = '';
|
|
464
|
+
let but = 'has not been found';
|
|
463
465
|
|
|
464
466
|
if (this.responses.length !== 0) {
|
|
465
|
-
const
|
|
467
|
+
const normalize = (t) => `${t}`.toLocaleLowerCase().replace(/\s+/g, ' ').trim();
|
|
468
|
+
const normalizedText = normalize(text);
|
|
469
|
+
const search = tokenize(normalizedText);
|
|
466
470
|
const last = this.responses[this.responses.length - 1];
|
|
467
471
|
const quickReplys = asserts.getQuickReplies(last);
|
|
468
|
-
|
|
472
|
+
let res = quickReplys
|
|
469
473
|
.filter(({ title = '', payload }) => title && payload && tokenize(title) === search);
|
|
470
474
|
|
|
471
|
-
if (res
|
|
475
|
+
if (res.length > 1) {
|
|
476
|
+
res = res
|
|
477
|
+
.filter(({ title = '' }) => normalize(title) === normalizedText);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (res.length === 1) {
|
|
472
481
|
const { title, payload } = res[0];
|
|
473
482
|
await this.processMessage(Request.quickReplyText(this.senderId, title, payload));
|
|
474
483
|
return true;
|
|
475
484
|
}
|
|
485
|
+
|
|
486
|
+
if (res.length > 1) {
|
|
487
|
+
but = 'found multiple occurences';
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
found = ` (found: ${quickReplys.map((q) => q.title).filter((q) => !!q).join(', ')})`;
|
|
476
491
|
}
|
|
477
492
|
|
|
478
|
-
|
|
493
|
+
throw new Error(`Quick reply "${text}" was required, but ${but}.${found}`);
|
|
479
494
|
}
|
|
480
495
|
|
|
481
496
|
/**
|