wingbot 3.67.13 → 3.67.15
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 +1 -1
- package/src/BuildRouter.js +34 -2
- package/src/Responder.js +4 -1
- package/src/ReturnSender.js +19 -0
package/package.json
CHANGED
package/src/BuildRouter.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
6
|
const { decompress } = require('compress-json');
|
|
7
|
+
const { brotliCompress, brotliDecompress } = require('zlib');
|
|
8
|
+
const { promisify } = require('util');
|
|
7
9
|
const { default: fetch } = require('node-fetch');
|
|
8
10
|
const assert = require('assert');
|
|
9
11
|
const path = require('path');
|
|
@@ -223,6 +225,9 @@ class BuildRouter extends Router {
|
|
|
223
225
|
|
|
224
226
|
this._prebuiltGlobalIntents = null;
|
|
225
227
|
|
|
228
|
+
this._brotliCompress = promisify(brotliCompress);
|
|
229
|
+
this._brotliDecompress = promisify(brotliDecompress);
|
|
230
|
+
|
|
226
231
|
this.resources = defaultResourceMap();
|
|
227
232
|
|
|
228
233
|
this._loadBotAuthorization = 'token' in block ? block.token : null;
|
|
@@ -382,18 +387,19 @@ class BuildRouter extends Router {
|
|
|
382
387
|
}
|
|
383
388
|
|
|
384
389
|
if (snapshot) {
|
|
385
|
-
snapshot = await
|
|
390
|
+
snapshot = await this._updateConfig(configStorage, snapshot);
|
|
386
391
|
}
|
|
387
392
|
|
|
388
393
|
if (ts !== 0 && !snapshot) {
|
|
389
394
|
// probably someone has updated the configuration
|
|
390
395
|
snapshot = await configStorage.getConfig();
|
|
396
|
+
snapshot = await this._decompressIfCompressed(snapshot);
|
|
391
397
|
}
|
|
392
398
|
|
|
393
399
|
if (!snapshot || typeof snapshot !== 'object' || !Array.isArray(snapshot.blocks)) {
|
|
394
400
|
// there is no configuration, load it from server
|
|
395
401
|
snapshot = await this.loadBot();
|
|
396
|
-
snapshot = await
|
|
402
|
+
snapshot = await this._updateConfig(configStorage, snapshot);
|
|
397
403
|
}
|
|
398
404
|
|
|
399
405
|
// wait for running request
|
|
@@ -406,6 +412,32 @@ class BuildRouter extends Router {
|
|
|
406
412
|
}
|
|
407
413
|
}
|
|
408
414
|
|
|
415
|
+
async _updateConfig (configStorage, snapshot) {
|
|
416
|
+
const buf = await this._brotliCompress(Buffer.from(JSON.stringify(snapshot)));
|
|
417
|
+
const compressed = {
|
|
418
|
+
compression: 'brotli',
|
|
419
|
+
base64url: buf.toString('base64url'),
|
|
420
|
+
timestamp: snapshot.timestamp
|
|
421
|
+
};
|
|
422
|
+
const updated = await configStorage.updateConfig(compressed);
|
|
423
|
+
const decoded = await this._decompressIfCompressed(updated);
|
|
424
|
+
return decoded;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
async _decompressIfCompressed (snapshot) {
|
|
428
|
+
if (!snapshot || snapshot.compression !== 'brotli' || !snapshot.base64url) {
|
|
429
|
+
return snapshot;
|
|
430
|
+
}
|
|
431
|
+
const buf = Buffer.from(snapshot.base64url, 'base64url');
|
|
432
|
+
const data = await this._brotliDecompress(buf);
|
|
433
|
+
|
|
434
|
+
const parsed = JSON.parse(data.toString('utf8'));
|
|
435
|
+
return {
|
|
436
|
+
...parsed,
|
|
437
|
+
timestamp: snapshot.timestamp
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
|
|
409
441
|
/**
|
|
410
442
|
* Loads conversation configuration
|
|
411
443
|
*
|
package/src/Responder.js
CHANGED
|
@@ -247,7 +247,10 @@ class Responder {
|
|
|
247
247
|
limit,
|
|
248
248
|
onlyFlag
|
|
249
249
|
);
|
|
250
|
-
const { responseTexts = [] } =
|
|
250
|
+
const { responseTexts = [], requestTexts = [] } = this._messageSender;
|
|
251
|
+
transcript.push(...requestTexts.map((text) => ({
|
|
252
|
+
fromBot: false, text
|
|
253
|
+
})));
|
|
251
254
|
transcript.push(...responseTexts.map((text) => ({
|
|
252
255
|
fromBot: true, text
|
|
253
256
|
})));
|
package/src/ReturnSender.js
CHANGED
|
@@ -212,6 +212,25 @@ class ReturnSender {
|
|
|
212
212
|
return this._simulatesOptIn;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
/**
|
|
216
|
+
* @returns {string[]}
|
|
217
|
+
*/
|
|
218
|
+
get requestTexts () {
|
|
219
|
+
const text = extractText(this._incommingMessage);
|
|
220
|
+
|
|
221
|
+
if (!text) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const filter = this._confidentInput
|
|
226
|
+
? this.confidentInputFilter
|
|
227
|
+
: this.textFilter;
|
|
228
|
+
|
|
229
|
+
return [
|
|
230
|
+
filter(text).trim()
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
|
|
215
234
|
/**
|
|
216
235
|
* @returns {string[]}
|
|
217
236
|
*/
|