wingbot 3.33.0 → 3.34.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
|
@@ -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,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
|
|
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
|
-
|
|
471
|
+
let res = quickReplys
|
|
469
472
|
.filter(({ title = '', payload }) => title && payload && tokenize(title) === search);
|
|
470
473
|
|
|
471
|
-
if (res
|
|
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
|
-
|
|
494
|
+
throw new Error(`Quick reply "${text}" ${but}`);
|
|
479
495
|
}
|
|
480
496
|
|
|
481
497
|
/**
|
|
@@ -468,6 +468,7 @@ class CustomEntityDetectionModel {
|
|
|
468
468
|
return {
|
|
469
469
|
text: cleanText,
|
|
470
470
|
intents: [],
|
|
471
|
+
// @ts-ignore
|
|
471
472
|
entities
|
|
472
473
|
};
|
|
473
474
|
}
|
|
@@ -615,6 +616,28 @@ class CustomEntityDetectionModel {
|
|
|
615
616
|
return this;
|
|
616
617
|
}
|
|
617
618
|
|
|
619
|
+
/**
|
|
620
|
+
* Sets options to entity detector.
|
|
621
|
+
* Useful for disabling anonymization of local system entities.
|
|
622
|
+
*
|
|
623
|
+
* @param {string} name
|
|
624
|
+
* @param {object} options
|
|
625
|
+
* @param {boolean} [options.anonymize]
|
|
626
|
+
* @returns {this}
|
|
627
|
+
* @example
|
|
628
|
+
*
|
|
629
|
+
* ai.register('wingbot-model-name')
|
|
630
|
+
* .setDetectorOptions('phone', { anonymize: false })
|
|
631
|
+
* .setDetectorOptions('email', { anonymize: false })
|
|
632
|
+
*/
|
|
633
|
+
setDetectorOptions (name, options) {
|
|
634
|
+
if (!this._entityDetectors.has(name)) {
|
|
635
|
+
throw new Error('Can\'t set entity detector options. Entity "name" does not exist.');
|
|
636
|
+
}
|
|
637
|
+
Object.assign(this._entityDetectors.get(name), options);
|
|
638
|
+
return this;
|
|
639
|
+
}
|
|
640
|
+
|
|
618
641
|
async getPhrases () {
|
|
619
642
|
return this._getPhrases();
|
|
620
643
|
}
|