wingbot 3.39.0-alpha.1 → 3.39.0-alpha.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.39.0-alpha.1",
3
+ "version": "3.39.0-alpha.2",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/AiMatching.js CHANGED
@@ -191,7 +191,7 @@ class AiMatching {
191
191
  return returnIfEmpty;
192
192
  }
193
193
 
194
- _hbsOrFn (value, cb) {
194
+ _hbsOrFn (value) {
195
195
  if (typeof value === 'string') {
196
196
  let useValue = value;
197
197
  if (useValue.match(/^\$[a-zA-Z0-9_-]+$/)) {
@@ -199,13 +199,12 @@ class AiMatching {
199
199
  }
200
200
  if (useValue.match(/\{\{.+\}\}/)) {
201
201
  const compiler = handlebars.compile(useValue);
202
- return (data) => {
203
- const res = compiler(data);
204
- return cb(res);
205
- };
202
+ // @ts-ignore
203
+ compiler.template = useValue;
204
+ return compiler;
206
205
  }
207
206
  }
208
- return cb(value);
207
+ return value;
209
208
  }
210
209
 
211
210
  _normalizeComparisonArray (compare, op) {
@@ -220,7 +219,7 @@ class AiMatching {
220
219
  const [val] = arr;
221
220
 
222
221
  return [
223
- this._hbsOrFn(val, (r) => this._normalizeToNumber(r, 0))
222
+ this._hbsOrFn(val)
224
223
  ];
225
224
  }
226
225
 
@@ -228,12 +227,12 @@ class AiMatching {
228
227
  const [min, max] = arr;
229
228
 
230
229
  return [
231
- this._hbsOrFn(min, (r) => this._normalizeToNumber(r, -Infinity)),
232
- this._hbsOrFn(max, (r) => this._normalizeToNumber(r, Infinity))
230
+ this._hbsOrFn(min),
231
+ this._hbsOrFn(max)
233
232
  ];
234
233
  }
235
234
 
236
- return arr.map((cmp) => this._hbsOrFn(cmp, (r) => `${r}`));
235
+ return arr.map((cmp) => this._hbsOrFn(cmp));
237
236
  }
238
237
 
239
238
  _stringOpToOperation (op) {
@@ -285,6 +284,7 @@ class AiMatching {
285
284
  */
286
285
  getSetStateForEntityRules ({ entities }) {
287
286
  return entities.reduce((o, rule) => {
287
+
288
288
  if (rule instanceof RegExp) {
289
289
  return o;
290
290
  }
@@ -297,13 +297,13 @@ class AiMatching {
297
297
 
298
298
  if (rule.op === COMPARE.EQUAL
299
299
  && rule.compare
300
- && rule.compare.length === 1
301
- && typeof rule.compare[0] !== 'function') {
300
+ && rule.compare.length === 1) {
302
301
 
303
302
  const key = `@${rule.entity}`;
304
303
  const value = rule.compare[0];
305
304
 
306
- return Object.assign(o, vars.dialogContext(key, value));
305
+ // @ts-ignore
306
+ return vars.dialogContext(key, value && (value.template || value));
307
307
  }
308
308
  return o;
309
309
  }, {});
@@ -732,11 +732,15 @@ class AiMatching {
732
732
  : false;
733
733
  }
734
734
 
735
- const useCmp = (compare || [])
735
+ let useCmp = (compare || [])
736
736
  .map((c) => (typeof c === 'function'
737
737
  ? c(requestState)
738
738
  : c));
739
739
 
740
+ if ([COMPARE.EQUAL, COMPARE.NOT_EQUAL].includes(operation)) {
741
+ useCmp = useCmp.map((c) => (typeof c === 'string' ? c : `${c}`));
742
+ }
743
+
740
744
  switch (operation) {
741
745
  case COMPARE.EQUAL:
742
746
  return useCmp.length === 0 || useCmp.includes(`${value}`);
@@ -748,7 +752,8 @@ class AiMatching {
748
752
  if (normalized === null) {
749
753
  return false;
750
754
  }
751
- return normalized >= min && normalized <= max;
755
+ return normalized >= this._normalizeToNumber(min, -Infinity)
756
+ && normalized <= this._normalizeToNumber(max, Infinity);
752
757
  }
753
758
  case COMPARE.GT:
754
759
  case COMPARE.LT:
@@ -759,7 +764,7 @@ class AiMatching {
759
764
  if (normalized === null) {
760
765
  return false;
761
766
  }
762
- return this._numberComparison(op, cmp, normalized);
767
+ return this._numberComparison(op, this._normalizeToNumber(cmp, 0), normalized);
763
768
  }
764
769
  default:
765
770
  return true;
package/src/Request.js CHANGED
@@ -1137,7 +1137,15 @@ class Request {
1137
1137
  let { setState = {} } = res;
1138
1138
  for (const gi of this.globalIntents.values()) {
1139
1139
  if (gi.action === res.action) {
1140
- ({ entitiesSetState } = gi);
1140
+ entitiesSetState = { ...gi.entitiesSetState };
1141
+
1142
+ const values = Array.from(Object.values(entitiesSetState));
1143
+
1144
+ for (const value of values) {
1145
+ if (typeof value === 'function') {
1146
+ Object.assign(entitiesSetState, value(stateData(this)));
1147
+ }
1148
+ }
1141
1149
  }
1142
1150
  }
1143
1151
  const newState = {
@@ -208,6 +208,7 @@ function makeQuickReplies (replies, path = '', translate = (w) => w, quickReplyC
208
208
  }
209
209
  return o;
210
210
  }, {});
211
+
211
212
  setState = {
212
213
  ...entitiesSetState,
213
214
  ...setState