wingbot 3.65.4 → 3.65.6

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.65.4",
3
+ "version": "3.65.6",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/AiMatching.js CHANGED
@@ -461,6 +461,19 @@ class AiMatching {
461
461
  const regexpScore = this._matchRegexp(req, regexps, noIntentHandicap);
462
462
  const textLength = req.text().trim().length;
463
463
 
464
+ let useState;
465
+ if (stateless || intents.length === 0) {
466
+ useState = Object.entries(stateData(req))
467
+ .reduce((o, [k, v]) => {
468
+ if (k.startsWith('@')) {
469
+ return o;
470
+ }
471
+ return Object.assign(o, { [k]: v });
472
+ }, {});
473
+ } else {
474
+ useState = stateData(req);
475
+ }
476
+
464
477
  if (regexpScore !== 0 || (intents.length === 0 && regexps.length === 0)) {
465
478
 
466
479
  if (entities.length === 0) {
@@ -475,19 +488,6 @@ class AiMatching {
475
488
  };
476
489
  }
477
490
 
478
- let useState;
479
- if (stateless || intents.length === 0) {
480
- useState = Object.entries(stateData(req))
481
- .reduce((o, [k, v]) => {
482
- if (k.startsWith('@')) {
483
- return o;
484
- }
485
- return Object.assign(o, { [k]: v });
486
- }, {});
487
- } else {
488
- useState = stateData(req);
489
- }
490
-
491
491
  const {
492
492
  score, handicap, matched, metl
493
493
  } = this
@@ -561,7 +561,7 @@ class AiMatching {
561
561
  requestIntent,
562
562
  entities,
563
563
  req,
564
- stateless
564
+ useState
565
565
  );
566
566
 
567
567
  if (score > max) {
@@ -594,7 +594,7 @@ class AiMatching {
594
594
  * @param {Intent} requestIntent
595
595
  * @param {EntityExpression[]} wantedEntities
596
596
  * @param {AIRequest} req
597
- * @param {boolean} stateless
597
+ * @param {object} useState
598
598
  * @returns {{score:number,entities:Entity[]}}
599
599
  */
600
600
  _intentMatchingScore (
@@ -603,7 +603,7 @@ class AiMatching {
603
603
  requestIntent,
604
604
  wantedEntities,
605
605
  req,
606
- stateless = false
606
+ useState
607
607
  ) {
608
608
  if (wantedIntent !== requestIntent.intent) {
609
609
  return { score: 0, entities: [] };
@@ -625,7 +625,7 @@ class AiMatching {
625
625
  textLength,
626
626
  wantedEntities,
627
627
  useEntities,
628
- stateless ? {} : req.state,
628
+ useState,
629
629
  requestIntent.entities
630
630
  ? (x) => Math.atan((x - 0.76) * 40) / Math.atan((1 - 0.76) * 40)
631
631
  : (x) => x,
@@ -78,11 +78,14 @@ class GenericTemplate extends ButtonTemplate {
78
78
  *
79
79
  * @param {string} action - Button action (can be absolute or relative)
80
80
  * @param {object} [data={}] - Action data
81
+ * @param {object} [setState] - SetState data
81
82
  * @returns {this}
82
83
  *
83
84
  * @memberOf GenericTemplate
84
85
  */
85
- setElementActionPostback (action, data = {}) {
86
+ setElementActionPostback (action, data = {}, setState = null) {
87
+ const hasSetState = setState && Object.keys(setState).length !== 0;
88
+
86
89
  Object.assign(this._element, {
87
90
  default_action: {
88
91
  type: 'postback',
@@ -91,7 +94,8 @@ class GenericTemplate extends ButtonTemplate {
91
94
  data: {
92
95
  _ca: this.context.currentAction,
93
96
  ...data
94
- }
97
+ },
98
+ ...(hasSetState ? { setState } : {})
95
99
  })
96
100
  }
97
101
  });
@@ -134,6 +138,7 @@ class GenericTemplate extends ButtonTemplate {
134
138
  return this;
135
139
  }
136
140
 
141
+ // @ts-ignore
137
142
  getTemplate () {
138
143
  this._attachAndClearButtons();
139
144
  const res = {