wingbot 3.49.1 → 3.50.1

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.49.1",
3
+ "version": "3.50.1",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -53,6 +53,7 @@
53
53
  "tsd-jsdoc": "^2.5.0"
54
54
  },
55
55
  "dependencies": {
56
+ "@amplitude/ua-parser-js": "^0.7.31",
56
57
  "form-data": "^4.0.0",
57
58
  "graphql": "^15.8.0",
58
59
  "jsonwebtoken": "^9.0.0",
package/src/Processor.js CHANGED
@@ -608,7 +608,7 @@ class Processor extends EventEmitter {
608
608
  const interactive = isUserInteraction(req);
609
609
 
610
610
  const sessionExpired = interactive
611
- && (sessionTs + this.options.sessionDuration) < Date.now();
611
+ && (sessionTs + this.options.sessionDuration) < timestamp;
612
612
 
613
613
  if (sessionExpired || !sessionId) {
614
614
  sessionStart = timestamp;
@@ -3,6 +3,7 @@
3
3
  */
4
4
  'use strict';
5
5
 
6
+ const uaParserJs = require('@amplitude/ua-parser-js');
6
7
  const { replaceDiacritics, webalize } = require('webalize');
7
8
  const Ai = require('../Ai');
8
9
  const {
@@ -101,6 +102,9 @@ const {
101
102
  * @prop {string[]} [responseTexts]
102
103
  * @prop {string|null} [pagePath]
103
104
  * @prop {string|null} [pageCategory]
105
+ * @prop {string} [browserName]
106
+ * @prop {string} [deviceType]
107
+ * @prop {string} [osName]
104
108
  */
105
109
 
106
110
  /**
@@ -177,6 +181,7 @@ const {
177
181
  /**
178
182
  * @typedef {object} HandlerConfig
179
183
  * @prop {string} [pagePathVar]
184
+ * @prop {string} [userAgentVar]
180
185
  * @prop {string} [snapshot]
181
186
  * @prop {string} [botId]
182
187
  * @prop {string} [timeZone] - default UTC
@@ -232,6 +237,7 @@ function onInteractionHandler (
232
237
  botId,
233
238
  timeZone = 'UTC',
234
239
  pagePathVar = '§pathname',
240
+ userAgentVar = '§ua',
235
241
  pathCategoryExtractor = defaultPathExtractor,
236
242
  anonymize = (x) => x,
237
243
  userExtractor = (state) => null // eslint-disable-line no-unused-vars
@@ -259,7 +265,7 @@ function onInteractionHandler (
259
265
  req,
260
266
  actions,
261
267
  lastAction,
262
- state,
268
+ // state,
263
269
  // data,
264
270
  skill,
265
271
  events,
@@ -285,8 +291,11 @@ function onInteractionHandler (
285
291
  _sst: sessionStart,
286
292
  _sts: sessionTs,
287
293
  lang,
288
- [pagePathVar]: pagePath
289
- } = state;
294
+ [pagePathVar]: pagePath,
295
+ [userAgentVar]: userAgent
296
+ } = req.state;
297
+
298
+ const ua = uaParserJs(userAgent);
290
299
 
291
300
  const pageCategory = pathCategoryExtractor(pagePath);
292
301
 
@@ -328,7 +337,10 @@ function onInteractionHandler (
328
337
  responseTexts,
329
338
  sessionDuration: sessionTs - sessionStart,
330
339
  pagePath,
331
- pageCategory
340
+ pageCategory,
341
+ browserName: ua.browser.name || null,
342
+ deviceType: ua.device.type || null,
343
+ osName: ua.os.name || null
332
344
  };
333
345
 
334
346
  let sessionPromise;
@@ -72,6 +72,7 @@ function getLanguageText (translations, lang = null, disableDefaulting = false)
72
72
  // @ts-ignore
73
73
  foundText = translations.find((t) => t.l === lang);
74
74
  } else if (disableDefaulting) {
75
+ // @ts-ignore
75
76
  [foundText] = translations;
76
77
  }
77
78
  if (isTextObjectEmpty(foundText) && !disableDefaulting) {