wingbot 3.52.0 → 3.52.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.52.0",
3
+ "version": "3.52.1",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
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 {Function} - the middleware
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
 
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
- && !!this.message.text)
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
- if (tokenized && this.message.text) {
750
- return tokenize(this.message.text);
749
+ const { text } = this.message;
750
+
751
+ if (tokenized && text) {
752
+ return tokenize(text) || text.trim();
751
753
  }
752
754
 
753
- return this.message.text || this._stickerToSmile() || '';
755
+ return text || this._stickerToSmile() || '';
754
756
  }
755
757
 
756
758
  /**