wingbot 3.48.0 → 3.49.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.48.0",
3
+ "version": "3.49.0",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,6 +32,7 @@ const {
32
32
  * @prop {string} [label]
33
33
  * @prop {number} [value]
34
34
  * @prop {string} [lang]
35
+ * @prop {string|null} [pageCategory]
35
36
  */
36
37
 
37
38
  /**
@@ -60,6 +61,8 @@ const {
60
61
  * @prop {string} [intent]
61
62
  * @prop {number} [intentScore]
62
63
  * @prop {string[]|string} [entities]
64
+ * @prop {string|null} [pagePath]
65
+ * @prop {string|null} [pageCategory]
63
66
  * @prop {string[]|string} allActions
64
67
  * @prop {boolean} nonInteractive
65
68
  *
@@ -96,6 +99,8 @@ const {
96
99
  * @prop {number} [sessionStart]
97
100
  * @prop {number} [sessionDuration]
98
101
  * @prop {string[]} [responseTexts]
102
+ * @prop {string|null} [pagePath]
103
+ * @prop {string|null} [pageCategory]
99
104
  */
100
105
 
101
106
  /**
@@ -153,6 +158,12 @@ const {
153
158
  * @returns {string}
154
159
  */
155
160
 
161
+ /**
162
+ * @callback PathCategoryExtractor
163
+ * @param {string} pathName
164
+ * @returns {string}
165
+ */
166
+
156
167
  /**
157
168
  * @typedef {object} TrackingEvents
158
169
  * @prop {TrackingEvent[]} events
@@ -165,6 +176,7 @@ const {
165
176
 
166
177
  /**
167
178
  * @typedef {object} HandlerConfig
179
+ * @prop {string} [pagePathVar]
168
180
  * @prop {string} [snapshot]
169
181
  * @prop {string} [botId]
170
182
  * @prop {string} [timeZone] - default UTC
@@ -173,6 +185,7 @@ const {
173
185
  * @prop {IGALogger} [log] - console like logger
174
186
  * @prop {Anonymizer} [anonymize] - text anonymization function
175
187
  * @prop {UserExtractor} [userExtractor] - text anonymization function
188
+ * @prop {PathCategoryExtractor} [pathCategoryExtractor]
176
189
  */
177
190
 
178
191
  /**
@@ -192,6 +205,17 @@ const {
192
205
  * @returns {Promise}
193
206
  */
194
207
 
208
+ function defaultPathExtractor (pathName) {
209
+ if (!pathName) {
210
+ return null;
211
+ }
212
+
213
+ const [firstElem] = pathName.split('/')
214
+ .filter((e) => !!e);
215
+
216
+ return firstElem || '/';
217
+ }
218
+
195
219
  /**
196
220
  *
197
221
  * @param {HandlerConfig} config
@@ -207,6 +231,8 @@ function onInteractionHandler (
207
231
  snapshot,
208
232
  botId,
209
233
  timeZone = 'UTC',
234
+ pagePathVar = '§pathname',
235
+ pathCategoryExtractor = defaultPathExtractor,
210
236
  anonymize = (x) => x,
211
237
  userExtractor = (state) => null // eslint-disable-line no-unused-vars
212
238
  },
@@ -233,7 +259,7 @@ function onInteractionHandler (
233
259
  req,
234
260
  actions,
235
261
  lastAction,
236
- // state,
262
+ state,
237
263
  // data,
238
264
  skill,
239
265
  events,
@@ -258,8 +284,11 @@ function onInteractionHandler (
258
284
  _sid: sessionId,
259
285
  _sst: sessionStart,
260
286
  _sts: sessionTs,
261
- lang
262
- } = req.state;
287
+ lang,
288
+ [pagePathVar]: pagePath
289
+ } = state;
290
+
291
+ const pageCategory = pathCategoryExtractor(pagePath);
263
292
 
264
293
  const trackEvents = [];
265
294
 
@@ -297,7 +326,9 @@ function onInteractionHandler (
297
326
  timeZone,
298
327
  sessionStart,
299
328
  responseTexts,
300
- sessionDuration: sessionTs - sessionStart
329
+ sessionDuration: sessionTs - sessionStart,
330
+ pagePath,
331
+ pageCategory
301
332
  };
302
333
 
303
334
  let sessionPromise;
@@ -391,7 +422,9 @@ function onInteractionHandler (
391
422
  intentScore: score,
392
423
  entities: asArray(req.entities.map((e) => e.entity)),
393
424
  text,
394
- allActions
425
+ allActions,
426
+ pagePath,
427
+ pageCategory
395
428
  };
396
429
 
397
430
  const notHandled = actions.some((a) => a.match(/\*$/)) && !req.isQuickReply();
@@ -513,6 +546,7 @@ function onInteractionHandler (
513
546
  action,
514
547
  label,
515
548
  value,
549
+ pageCategory,
516
550
  ...langsExtension
517
551
  });
518
552
  }