wingbot 3.68.0-alpha.1 → 3.68.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.68.0-alpha.1",
3
+ "version": "3.68.0",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -21,6 +21,12 @@ const { shouldExecuteResolver } = require('./resolvers/resolverTags');
21
21
  const MESSAGE_RESOLVER_NAME = 'botbuild.message';
22
22
 
23
23
  /** @typedef {import('./Router').BaseConfiguration} BaseConfiguration */
24
+ /**
25
+ * @typedef {object} BuildInfo
26
+ * @prop {boolean} [expectedToAddResolver]
27
+ * @prop {boolean} [attachedRouter]
28
+ * @prop {boolean} [notLastMessage]
29
+ */
24
30
 
25
31
  /**
26
32
  *
@@ -869,8 +875,8 @@ class BuildRouter extends Router {
869
875
  /**
870
876
  *
871
877
  * @param {Resolver[]} resolvers
872
- * @param {TransformedRoute} route
873
- * @param {*} buildInfo
878
+ * @param {TransformedRoute} [route]
879
+ * @param {BuildInfo} [buildInfo]
874
880
  * @returns {Middleware<S,C>[]}
875
881
  */
876
882
  buildResolvers (resolvers, route = DUMMY_ROUTE, buildInfo = {}) {
@@ -891,7 +897,7 @@ class BuildRouter extends Router {
891
897
  const context = {
892
898
  ...this._resolvedContext,
893
899
  isLastIndex: lastIndex === i && !buildInfo.expectedToAddResolver,
894
- isLastMessage: lastMessageIndex === i,
900
+ isLastMessage: lastMessageIndex === i && !buildInfo.notLastMessage,
895
901
  router: this,
896
902
  linksMap: this._linksMap,
897
903
  path: ctxPath,
@@ -918,7 +924,7 @@ class BuildRouter extends Router {
918
924
  *
919
925
  * @param {Resolver} resolver
920
926
  * @param {BotContext<C>} context
921
- * @param {*} buildInfo
927
+ * @param {BuildInfo} buildInfo
922
928
  * @returns {Middleware<S,C>}
923
929
  */
924
930
  _resolverFactory (resolver, context, buildInfo) {
package/src/Plugins.js CHANGED
@@ -40,6 +40,11 @@ const wrapPluginFunction = require('./utils/wrapPluginFunction');
40
40
  * @returns {Router<S,C>|Middleware<S,C>}
41
41
  */
42
42
 
43
+ /**
44
+ * @typedef {object} PluginFactoryOptions
45
+ * @prop {string[]} [notLastMessageItems]
46
+ */
47
+
43
48
  /**
44
49
  * Custom code plugins for BuildRouter and wingbot.ai
45
50
  *
@@ -53,7 +58,22 @@ class Plugins {
53
58
  this._plugins = new Map();
54
59
  }
55
60
 
56
- getPluginFactory (name, paramsData = {}, configuration = {}, defaultPlugin = null) {
61
+ /**
62
+ *
63
+ * @param {string} name
64
+ * @returns {PluginFactoryOptions}
65
+ */
66
+ getPluginOptions (name) {
67
+ const plugin = this._getPlug(name, {});
68
+
69
+ if (plugin && plugin.options) {
70
+ return plugin.options;
71
+ }
72
+
73
+ return {};
74
+ }
75
+
76
+ _getPlug (name, defaultPlugin) {
57
77
  let plugin;
58
78
  if (plugins.has(name)) {
59
79
  plugin = plugins.get(name);
@@ -64,6 +84,11 @@ class Plugins {
64
84
  } else {
65
85
  throw new Error(`Unknown Plugin: ${name}. Ensure its registration.`);
66
86
  }
87
+ return plugin;
88
+ }
89
+
90
+ getPluginFactory (name, paramsData = {}, configuration = {}, defaultPlugin = null) {
91
+ const plugin = this._getPlug(name, defaultPlugin);
67
92
  if (plugin && plugin.pluginFactory) {
68
93
  return plugin.pluginFactory(paramsData, configuration);
69
94
  }
@@ -174,13 +199,14 @@ class Plugins {
174
199
  *
175
200
  * @param {string} name - plugin name or plugins object to include
176
201
  * @param {PluginFactory<S,C>} pluginFactory - function, which returns a plugin
202
+ * @param {PluginFactoryOptions} [options]
177
203
  */
178
- registerFactory (name, pluginFactory) {
204
+ registerFactory (name, pluginFactory, options = {}) {
179
205
  if (typeof pluginFactory !== 'function') {
180
206
  // eslint-disable-next-line no-console
181
207
  console.warn(`Plugin factory expected, ${typeof pluginFactory} given (plugin: ${name})`);
182
208
  }
183
- this._plugins.set(name, { pluginFactory });
209
+ this._plugins.set(name, { pluginFactory, options });
184
210
  }
185
211
 
186
212
  }
package/src/Responder.js CHANGED
@@ -48,7 +48,8 @@ Object.freeze(ExpectedInput);
48
48
  * @typedef {object} ExpectedInputOptions
49
49
  * @prop {string} [url]
50
50
  * @prop {string} [webview_height_ratio]
51
- * @prop {string} [on_close_payload]
51
+ * @prop {string} [onCloseAction]
52
+ * @prop {string} [onCloseActionData]
52
53
  */
53
54
 
54
55
  /**
@@ -907,8 +908,14 @@ class Responder {
907
908
  * });
908
909
  */
909
910
  expectedInput (type, options = {}) {
911
+ const { onCloseAction, onCloseActionData = {}, ...rest } = options;
912
+ if (onCloseAction) {
913
+ Object.assign(rest, {
914
+ on_close_payload: this._makePayload(onCloseAction, onCloseActionData)
915
+ });
916
+ }
910
917
  this._messageSender.send({
911
- expectedIntentsAndEntities: [{ type, ...options }]
918
+ expectedIntentsAndEntities: [{ type, ...rest }]
912
919
  });
913
920
  return this;
914
921
  }
@@ -1063,16 +1070,20 @@ class Responder {
1063
1070
  return this.template({
1064
1071
  template_type: 'one_time_notif_req',
1065
1072
  title: this._t(title),
1066
- payload: JSON.stringify({
1067
- action: makeAbsolute(action, this.path),
1068
- data: {
1069
- ...data,
1070
- _ntfTag: tag
1071
- }
1073
+ payload: this._makePayload(action, {
1074
+ ...data,
1075
+ _ntfTag: tag
1072
1076
  })
1073
1077
  });
1074
1078
  }
1075
1079
 
1080
+ _makePayload (action, data) {
1081
+ return JSON.stringify({
1082
+ action: makeAbsolute(action, this.path),
1083
+ data
1084
+ });
1085
+ }
1086
+
1076
1087
  template (payload) {
1077
1088
  const messageData = {
1078
1089
  message: {
@@ -29,10 +29,15 @@ function plugin (params, context, plugins) {
29
29
  } = params;
30
30
  const { router, allowForbiddenSnippetWords } = context;
31
31
 
32
+ const options = plugins.getPluginOptions(codeBlockId);
33
+
32
34
  const itemsMap = Object.keys(items)
33
35
  .reduce((map, itemName) => {
34
36
  const item = items[itemName];
35
- const builtResolvers = router.buildResolvers(item.resolvers);
37
+ const builtResolvers = router.buildResolvers(item.resolvers, undefined, {
38
+ notLastMessage: Array.isArray(options.notLastMessageItems)
39
+ && options.notLastMessageItems.includes(itemName)
40
+ });
36
41
 
37
42
  map.set(itemName, builtResolvers);
38
43