wingbot 3.52.0 → 3.52.2-alpha.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/Ai.js +2 -1
- package/src/AiMatching.js +11 -4
- package/src/Request.js +6 -4
package/package.json
CHANGED
package/src/Ai.js
CHANGED
|
@@ -44,6 +44,7 @@ let uq = 1;
|
|
|
44
44
|
/** @typedef {import('./Request').IntentAction} IntentAction */
|
|
45
45
|
/** @typedef {import('./Request')} Request */
|
|
46
46
|
/** @typedef {import('./Responder')} Responder */
|
|
47
|
+
/** @typedef {import('./Router').Resolver} Resolver */
|
|
47
48
|
/** @typedef {import('./wingbot/CachedModel').Result} Result */
|
|
48
49
|
/** @typedef {import('./wingbot/CustomEntityDetectionModel').Phrases} Phrases */
|
|
49
50
|
/** @typedef {import('./wingbot/CustomEntityDetectionModel').EntityDetector} EntityDetector */
|
|
@@ -412,7 +413,7 @@ class Ai {
|
|
|
412
413
|
* - emojis (`'#😄🙃😛'`)
|
|
413
414
|
*
|
|
414
415
|
* @param {IntentRule|IntentRule[]} intent
|
|
415
|
-
* @returns {
|
|
416
|
+
* @returns {Resolver} - the middleware
|
|
416
417
|
* @memberOf Ai
|
|
417
418
|
* @example
|
|
418
419
|
* const { Router, ai } = require('wingbot');
|
package/src/AiMatching.js
CHANGED
|
@@ -352,6 +352,11 @@ class AiMatching {
|
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
+
_escapeRegExp (string) {
|
|
356
|
+
return string
|
|
357
|
+
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
358
|
+
}
|
|
359
|
+
|
|
355
360
|
/**
|
|
356
361
|
* Create a rule to be cached inside a routing structure
|
|
357
362
|
*
|
|
@@ -402,7 +407,7 @@ class AiMatching {
|
|
|
402
407
|
} else {
|
|
403
408
|
regexText = exp.replace(/^#/, '')
|
|
404
409
|
.split('|')
|
|
405
|
-
.map((s) => `^${s}$`.toLowerCase())
|
|
410
|
+
.map((s) => `^${this._escapeRegExp(s)}$`.toLowerCase())
|
|
406
411
|
.join('|');
|
|
407
412
|
}
|
|
408
413
|
|
|
@@ -669,19 +674,21 @@ class AiMatching {
|
|
|
669
674
|
._entityIsMatching(wanted.op, wanted.compare, undefined, requestState);
|
|
670
675
|
}
|
|
671
676
|
|
|
672
|
-
if (!matching && !wanted.optional) {
|
|
677
|
+
if (!matching && (!wanted.optional || requestEntity)) {
|
|
673
678
|
return {
|
|
674
679
|
score: 0, handicap: 0, matched: [], minScore, fromState
|
|
675
680
|
};
|
|
676
681
|
}
|
|
677
682
|
|
|
678
|
-
if (!matching) { // optional
|
|
683
|
+
if (!matching) { // && optional && !requestEntity
|
|
679
684
|
handicap += this.redundantEntityHandicap;
|
|
680
685
|
continue;
|
|
681
686
|
}
|
|
682
687
|
|
|
683
688
|
if (wanted.optional) {
|
|
684
|
-
handicap +=
|
|
689
|
+
handicap += wanted.op
|
|
690
|
+
? this.optionalHandicap
|
|
691
|
+
: (this.optionalHandicap * 2);
|
|
685
692
|
}
|
|
686
693
|
|
|
687
694
|
if (wanted.op === COMPARE.NOT_EQUAL) {
|
package/src/Request.js
CHANGED
|
@@ -688,7 +688,7 @@ class Request {
|
|
|
688
688
|
return (this._postback === null
|
|
689
689
|
&& this.message !== null
|
|
690
690
|
&& !this.message.quick_reply
|
|
691
|
-
&&
|
|
691
|
+
&& typeof this.message.text === 'string')
|
|
692
692
|
|| this._stickerToSmile() !== '';
|
|
693
693
|
}
|
|
694
694
|
|
|
@@ -746,11 +746,13 @@ class Request {
|
|
|
746
746
|
return '';
|
|
747
747
|
}
|
|
748
748
|
|
|
749
|
-
|
|
750
|
-
|
|
749
|
+
const { text } = this.message;
|
|
750
|
+
|
|
751
|
+
if (tokenized && text) {
|
|
752
|
+
return tokenize(text) || text.trim();
|
|
751
753
|
}
|
|
752
754
|
|
|
753
|
-
return
|
|
755
|
+
return text || this._stickerToSmile() || '';
|
|
754
756
|
}
|
|
755
757
|
|
|
756
758
|
/**
|