wingbot 3.40.1 → 3.41.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.40.1",
3
+ "version": "3.41.0",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,3 +1,5 @@
1
+
2
+ const { compileWithState } = require('../../src/utils');
1
3
  const { StepState, getNextStep } = require('../../src/utils/slots');
2
4
 
3
5
  /** @typedef {import('../../src/Router').Resolver} Resolver */
@@ -7,9 +9,13 @@ const { StepState, getNextStep } = require('../../src/utils/slots');
7
9
  /** @typedef {import('../../src/utils/slots').SlotsRequest} SlotsRequest */
8
10
 
9
11
  /**
12
+ * @param {object} params
13
+ * @param {string} [params.skip]
10
14
  * @returns {SlotsResolver}
11
15
  */
12
- function slotContinue () {
16
+ function slotsContinue ({
17
+ skip
18
+ }) {
13
19
 
14
20
  /**
15
21
  * @param {SlotsRequest} req
@@ -17,7 +23,7 @@ function slotContinue () {
17
23
  * @param {Function} postBack
18
24
  * @returns {Promise}
19
25
  */
20
- async function slotContinuePlugin (req, res, postBack) {
26
+ async function slotsContinuePlugin (req, res, postBack) {
21
27
  const state = { ...req.state, ...res.newState };
22
28
 
23
29
  const { _slotStep: step } = state;
@@ -28,16 +34,27 @@ function slotContinue () {
28
34
  res.text(msg);
29
35
  throw new Error(msg);
30
36
  }
31
- slotState = slotState.map((s) => (s.e === step.entity
32
- ? { ...s, s: StepState.FILLED }
33
- : s));
37
+
38
+ const skipEntities = compileWithState(req, res, skip)
39
+ .split(',')
40
+ .map((e) => e.trim());
41
+
42
+ slotState = slotState.map((s) => {
43
+ if (skipEntities.includes(s.e)) {
44
+ return { ...s, s: StepState.INITIALIZED }
45
+ }
46
+
47
+ return s.e === step.entity
48
+ ? { ...s, s: StepState.FILLED }
49
+ : s;
50
+ });
34
51
 
35
52
  res.setState({ _slotState: slotState });
36
53
 
37
54
  return getNextStep(req, res, postBack);
38
55
  }
39
56
 
40
- return slotContinuePlugin;
57
+ return slotsContinuePlugin;
41
58
  }
42
59
 
43
- module.exports = slotContinue;
60
+ module.exports = slotsContinue;
@@ -442,11 +442,19 @@
442
442
  {
443
443
  "id": "ai.wingbot.slotsContinue",
444
444
  "name": "Slot filling: continue",
445
- "description": "move the slot filling to the next step",
445
+ "description": "Move the slot filling to the next step",
446
446
  "availableSince": 3.39,
447
447
  "editable": false,
448
448
  "isFactory": true,
449
449
  "inputs": [
450
+ {
451
+ "name": "skip",
452
+ "label": "Skip to entity (reset entities)",
453
+ "type": "text",
454
+ "validations": [
455
+ { "type": "regexp", "value": "^\\s*@[a-zA-Z0-9-]+\\s*(,\\s*@[a-zA-Z0-9-]+\\s*)*$", "message": "the entity for the slot filling should be valid" }
456
+ ]
457
+ }
450
458
  ],
451
459
  "items": [
452
460
  ]
package/src/Plugins.js CHANGED
@@ -42,7 +42,7 @@ const wrapPluginFunction = require('./utils/wrapPluginFunction');
42
42
  * Custom code plugins for BuildRouter and wingbot.ai
43
43
  *
44
44
  * @template {object} [S=object]
45
- * @template {object} C=Object
45
+ * @template {object} [C=Object]
46
46
  * @class Plugins
47
47
  */
48
48
  class Plugins {
@@ -72,7 +72,7 @@ class Plugins {
72
72
  *
73
73
  * @param {string} name
74
74
  * @param {object} [paramsData]
75
- * @param {Map<string,Function[]>|Object<string,Function>} [items]
75
+ * @param {Map<string,Function[]>|Object<string,Middleware<S>>} [items]
76
76
  * @param {object} [context]
77
77
  * @param {boolean} [context.isLastIndex]
78
78
  * @param {Router} [context.router]
@@ -104,6 +104,7 @@ class Plugins {
104
104
  let useItems = items;
105
105
 
106
106
  if (!(items instanceof Map)) {
107
+ // @ts-ignore
107
108
  useItems = new Map(
108
109
  Object.keys(items)
109
110
  .map((key) => [
package/src/Responder.js CHANGED
@@ -25,7 +25,8 @@ const EXCEPTION_HOPCOUNT_THRESHOLD = 5;
25
25
  /** @typedef {import('./Request')} Request */
26
26
 
27
27
  /**
28
- * @enum {string}
28
+ * @enum {string} ExpectedInput
29
+ * @readonly
29
30
  */
30
31
  const ExpectedInput = {
31
32
  TYPE_PASSWORD: 'password'
@@ -95,7 +96,7 @@ class Responder {
95
96
  };
96
97
 
97
98
  /**
98
- * @type {Object<string,ExpectedInput>}
99
+ * @prop {Object<keyof ExpectedInput,ExpectedInput>}
99
100
  */
100
101
  this.ExpectedInputTypes = ExpectedInput;
101
102
 
package/src/Tester.js CHANGED
@@ -230,6 +230,8 @@ class Tester {
230
230
  && !(res.status === 204 && this._pluginBlocksCollector.length > 0)
231
231
  && !(res.status === 204 && this.allowEmptyResponse)) {
232
232
 
233
+ this.debug();
234
+
233
235
  if (res.status === 204) {
234
236
  throw Object.assign(new Error(`Bot did not respond (status ${res.status})`), { code: res.status });
235
237
  }
@@ -21,6 +21,7 @@ const stateData = require('./stateData');
21
21
  * @param {Request} req
22
22
  * @param {Responder} res
23
23
  * @param {string} template
24
+ * @returns {string}
24
25
  * @example
25
26
  *
26
27
  * const { compileWithState } = require('wingbot');
@@ -69,13 +69,19 @@ const StepState = {
69
69
  async function getNextStep (req, res, postBack) {
70
70
  let invalid = null;
71
71
  const {
72
- _slotState: slotState, _slotSteps: steps, _slotDone: doneAction
72
+ _slotState: slotState, _slotSteps: steps, _slotDone: doneAction, ...rest
73
73
  } = { ...req.state, ...res.newState };
74
74
 
75
75
  for (const slot of slotState) {
76
76
  const step = steps.find((s) => s.entity === slot.e);
77
+ if (step && slot.s === StepState.INITIALIZED && (
78
+ (step.type !== StepType.MULTI && rest[slot.e])
79
+ || (step.type === StepType.MULTI && rest[slot.e.replace(/^@/, '+')] && rest[slot.e.replace(/^@/, '+')].length))) {
80
+
81
+ slot.s = StepState.FILLED;
82
+ }
83
+
77
84
  if (slot.s === StepState.FILLED && step && step.validateAction) {
78
- // eslint-disable-next-line
79
85
  await postBack(step.validateAction, {}, true);
80
86
  if (res.finalMessageSent) {
81
87
  invalid = step;