wingbot 3.68.5 → 3.68.8

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.5",
3
+ "version": "3.68.8",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -10,7 +10,7 @@
10
10
  "doc": "npm run doc:gql && node ./bin/makeApiDoc.js && cpy ./CHANGELOG.md ./doc && gitbook install ./doc && gitbook build ./doc && rimraf -rf ./docs && rimraf --rf ./doc/CHANGELOG.md && move-cli ./doc/_book ./docs",
11
11
  "test": "npm run test:lint && npm run test:coverage && npm run test:coverage:threshold",
12
12
  "test:coverage": "nyc --reporter=html mocha ./test && nyc report",
13
- "test:coverage:threshold": "nyc check-coverage --lines 89 --functions 88 --branches 80",
13
+ "test:coverage:threshold": "nyc check-coverage --lines 89 --functions 88 --branches 79",
14
14
  "test:backend": "mocha ./test",
15
15
  "test:lint": "eslint --ext .js src test *.js plugins"
16
16
  },
@@ -19,6 +19,7 @@ const defaultResourceMap = require('./defaultResourceMap');
19
19
  const { shouldExecuteResolver } = require('./resolvers/resolverTags');
20
20
 
21
21
  const MESSAGE_RESOLVER_NAME = 'botbuild.message';
22
+ const PLUGIN_RESOLVER_NAME = 'botbuild.plugin';
22
23
 
23
24
  /** @typedef {import('./Router').BaseConfiguration} BaseConfiguration */
24
25
  /**
@@ -41,6 +42,7 @@ const MESSAGE_RESOLVER_NAME = 'botbuild.message';
41
42
  * @prop {string} type
42
43
  * @prop {object} params
43
44
  * @prop {string} [params.staticBlockId]
45
+ * @prop {object} [params.items]
44
46
  * @prop {string} [tag]
45
47
  */
46
48
 
@@ -865,7 +867,10 @@ class BuildRouter extends Router {
865
867
  */
866
868
  _lastMessageIndex (resolvers) {
867
869
  for (let i = resolvers.length - 1; i >= 0; i--) {
868
- if (resolvers[i].type === MESSAGE_RESOLVER_NAME) {
870
+ const { type, params = {} } = resolvers[i];
871
+ if (MESSAGE_RESOLVER_NAME === type
872
+ || (type === PLUGIN_RESOLVER_NAME
873
+ && params && params.items && Object.keys(params.items).length)) {
869
874
  return i;
870
875
  }
871
876
  }
package/src/Responder.js CHANGED
@@ -251,7 +251,7 @@ class Responder {
251
251
  * @returns {Promise<Transcript[]>}
252
252
  */
253
253
  async getTranscript (limit = 10, onlyFlag = null, skipThisTurnaround = false) {
254
- const { chatLogStorage } = this._messageSender;
254
+ const { chatLogStorage, timestamp } = this._messageSender;
255
255
  if (!chatLogStorage) {
256
256
  return [];
257
257
  }
@@ -265,10 +265,10 @@ class Responder {
265
265
  if (!skipThisTurnaround) {
266
266
  const { responseTexts = [], requestTexts = [] } = this._messageSender;
267
267
  transcript.push(...requestTexts.map((text) => ({
268
- fromBot: false, text
268
+ fromBot: false, text, timestamp
269
269
  })));
270
270
  transcript.push(...responseTexts.map((text) => ({
271
- fromBot: true, text
271
+ fromBot: true, text, timestamp
272
272
  })));
273
273
  }
274
274
  return transcript;
@@ -103,6 +103,8 @@ class ReturnSender {
103
103
 
104
104
  this._features = Array.isArray(incommingMessage.features) ? incommingMessage.features : ['text'];
105
105
 
106
+ this.timestamp = incommingMessage.timestamp;
107
+
106
108
  this._sendLastMessageWithFinish = this._features.includes(FEATURE_PHRASES)
107
109
  || this._features.includes(FEATURE_TRACKING);
108
110
 
@@ -5,16 +5,52 @@
5
5
 
6
6
  /** @typedef {import('./transcriptFromHistory').Transcript} Transcript */
7
7
 
8
+ /**
9
+ * @typedef {object} Options
10
+ * @prop {string} [timezone]
11
+ * @prop {string} [locale]
12
+ */
13
+
8
14
  /**
9
15
  * @param {Transcript[]} transcript
10
16
  * @param {string} [userSide]
11
17
  * @param {string} [botSide]
18
+ * @param {Options} [options]
12
19
  * @returns {string}
13
20
  */
14
- function htmlBodyFromTranscript (transcript, userSide = 'User', botSide = 'Bot') {
21
+ function htmlBodyFromTranscript (transcript, userSide = 'User', botSide = 'Bot', options = {}) {
22
+
23
+ let lastDate = null;
24
+ let lastTime = null;
25
+ const showDate = options.locale && options.timezone;
15
26
 
16
27
  return transcript
17
- .map((msg) => `<b>${msg.fromBot ? botSide : userSide}:</b> ${msg.text}`)
28
+ .flatMap((msg) => {
29
+ const line = `<b>${msg.fromBot ? botSide : userSide}:</b> ${msg.text}`;
30
+
31
+ if (!showDate || !msg.timestamp) {
32
+ return [line];
33
+ }
34
+
35
+ const d = new Date(msg.timestamp);
36
+
37
+ const date = d.toLocaleDateString(options.locale, {
38
+ year: 'numeric', month: 'numeric', day: 'numeric', timeZone: options.timezone
39
+ });
40
+ const time = d.toLocaleTimeString(options.locale, {
41
+ hour: 'numeric', minute: 'numeric', timeZone: options.timezone
42
+ });
43
+
44
+ if (lastTime === time && lastDate === time) {
45
+ return [line];
46
+ }
47
+
48
+ const timeLine = `<i>(${lastDate === date ? '' : `${date} `}${time})</i></small>`;
49
+ lastDate = date;
50
+ lastTime = time;
51
+
52
+ return [timeLine, line];
53
+ })
18
54
  .join('<br />');
19
55
  }
20
56
 
@@ -22,6 +22,7 @@ const extractText = require('./extractText');
22
22
  * @typedef {object} Transcript
23
23
  * @prop {string} text
24
24
  * @prop {boolean} fromBot
25
+ * @prop {number} [timestamp]
25
26
  */
26
27
 
27
28
  /**
@@ -51,12 +52,17 @@ async function transcriptFromHistory (
51
52
 
52
53
  return data
53
54
  .map((turn) => {
55
+ let { timestamp } = turn;
54
56
  const { request, responses = [] } = turn;
55
57
 
58
+ if (!timestamp) {
59
+ timestamp = request.timestamp || null;
60
+ }
61
+
56
62
  return [
57
- { fromBot: false, text: extractText(request) },
63
+ { fromBot: false, text: extractText(request), timestamp },
58
64
  ...responses
59
- .map((response) => ({ fromBot: true, text: extractText(response) }))
65
+ .map((response) => ({ fromBot: true, text: extractText(response), timestamp }))
60
66
  ];
61
67
  })
62
68
  .reduce((ret, arr) => [...ret, ...arr], [])