botium-core 1.12.1 → 1.12.4

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/dist/botium-es.js CHANGED
@@ -36,7 +36,7 @@ import express from 'express';
36
36
  import bodyParser from 'body-parser';
37
37
 
38
38
  var name = "botium-core";
39
- var version$1 = "1.12.1";
39
+ var version$1 = "1.12.4";
40
40
  var description = "The Selenium for Chatbots";
41
41
  var main = "index.js";
42
42
  var module = "dist/botium-es.js";
@@ -68,23 +68,23 @@ var bugs = {
68
68
  };
69
69
  var homepage = "https://www.botium.ai";
70
70
  var dependencies = {
71
- "@babel/runtime": "^7.16.7",
71
+ "@babel/runtime": "^7.17.8",
72
72
  async: "^3.2.3",
73
- "body-parser": "^1.19.1",
74
- boolean: "^3.1.4",
73
+ "body-parser": "^1.19.2",
74
+ boolean: "^3.2.0",
75
75
  bottleneck: "^2.19.5",
76
76
  "csv-parse": "^5.0.4",
77
- debug: "^4.3.3",
77
+ debug: "^4.3.4",
78
78
  esprima: "^4.0.1",
79
- express: "^4.17.2",
79
+ express: "^4.17.3",
80
80
  globby: "11.0.4",
81
- ioredis: "^4.28.3",
81
+ ioredis: "^4.28.5",
82
82
  "is-class": "^0.0.9",
83
83
  "is-json": "^2.0.1",
84
84
  jsonpath: "^1.1.1",
85
85
  lodash: "^4.17.21",
86
86
  "markdown-it": "^12.3.2",
87
- "mime-types": "^2.1.34",
87
+ "mime-types": "^2.1.35",
88
88
  mkdirp: "^1.0.4",
89
89
  moment: "^2.29.1",
90
90
  mustache: "^4.2.0",
@@ -101,21 +101,21 @@ var dependencies = {
101
101
  "swagger-jsdoc": "^6.1.0",
102
102
  "swagger-ui-express": "^4.3.0",
103
103
  uuid: "^8.3.2",
104
- vm2: "^3.9.5",
104
+ vm2: "^3.9.9",
105
105
  "write-yaml": "^1.0.0",
106
- xlsx: "^0.17.5",
106
+ xlsx: "^0.18.4",
107
107
  xregexp: "^5.1.0",
108
108
  yaml: "^1.10.2"
109
109
  };
110
110
  var devDependencies = {
111
- "@babel/core": "^7.16.12",
111
+ "@babel/core": "^7.17.8",
112
112
  "@babel/node": "^7.16.8",
113
- "@babel/plugin-transform-runtime": "^7.16.10",
113
+ "@babel/plugin-transform-runtime": "^7.17.0",
114
114
  "@babel/preset-env": "^7.16.11",
115
- chai: "^4.3.4",
115
+ chai: "^4.3.6",
116
116
  "chai-as-promised": "^7.1.1",
117
117
  "cross-env": "^7.0.3",
118
- eslint: "^8.7.0",
118
+ eslint: "^8.11.0",
119
119
  "eslint-config-standard": "^16.0.3",
120
120
  "eslint-plugin-import": "^2.25.4",
121
121
  "eslint-plugin-node": "^11.1.0",
@@ -123,11 +123,11 @@ var devDependencies = {
123
123
  "eslint-plugin-standard": "^4.1.0",
124
124
  "license-checker": "^25.0.1",
125
125
  "license-compatibility-checker": "^0.3.5",
126
- mocha: "^9.2.0",
127
- nock: "^13.2.2",
128
- "npm-check-updates": "^12.2.1",
126
+ mocha: "^9.2.2",
127
+ nock: "^13.2.4",
128
+ "npm-check-updates": "^12.5.4",
129
129
  nyc: "^15.1.0",
130
- rollup: "^2.66.0",
130
+ rollup: "^2.70.1",
131
131
  "rollup-plugin-babel": "^4.4.0",
132
132
  "rollup-plugin-commonjs": "^10.1.0",
133
133
  "rollup-plugin-json": "^4.0.0",
@@ -244,6 +244,11 @@ var Capabilities = {
244
244
  SIMPLEREST_RESPONSE_HOOK: 'SIMPLEREST_RESPONSE_HOOK',
245
245
  SIMPLEREST_MEDIA_JSONPATH: 'SIMPLEREST_MEDIA_JSONPATH',
246
246
  SIMPLEREST_BUTTONS_JSONPATH: 'SIMPLEREST_BUTTONS_JSONPATH',
247
+ SIMPLEREST_CARDS_JSONPATH: 'SIMPLEREST_CARDS_JSONPATH',
248
+ SIMPLEREST_CARD_TEXT_JSONPATH: 'SIMPLEREST_CARD_TEXT_JSONPATH',
249
+ SIMPLEREST_CARD_SUBTEXT_JSONPATH: 'SIMPLEREST_CARD_SUBTEXT_JSONPATH',
250
+ SIMPLEREST_CARD_BUTTONS_JSONPATH: 'SIMPLEREST_CARD_BUTTONS_JSONPATH',
251
+ SIMPLEREST_CARD_ATTACHMENTS_JSONPATH: 'SIMPLEREST_CARD_ATTACHMENTS_JSONPATH',
247
252
  SIMPLEREST_CONTEXT_JSONPATH: 'SIMPLEREST_CONTEXT_JSONPATH',
248
253
  SIMPLEREST_CONTEXT_MERGE_OR_REPLACE: 'SIMPLEREST_CONTEXT_MERGE_OR_REPLACE',
249
254
  SIMPLEREST_CONVERSATION_ID_TEMPLATE: 'SIMPLEREST_CONVERSATION_ID_TEMPLATE',
@@ -314,6 +319,7 @@ var Capabilities = {
314
319
  // API Calls Rate Limiting
315
320
  RATELIMIT_USERSAYS_MAXCONCURRENT: 'RATELIMIT_USERSAYS_MAXCONCURRENT',
316
321
  RATELIMIT_USERSAYS_MINTIME: 'RATELIMIT_USERSAYS_MINTIME',
322
+ RATELIMIT_BOTTLENECK_FN: 'RATELIMIT_BOTTLENECK_FN',
317
323
  SECURITY_ALLOW_UNSAFE: 'SECURITY_ALLOW_UNSAFE',
318
324
  PRECOMPILERS: 'PRECOMPILERS'
319
325
  };
@@ -389,6 +395,11 @@ Capabilities.SIMPLEREST_RESPONSE_JSONPATH;
389
395
  Capabilities.SIMPLEREST_RESPONSE_HOOK;
390
396
  Capabilities.SIMPLEREST_MEDIA_JSONPATH;
391
397
  Capabilities.SIMPLEREST_BUTTONS_JSONPATH;
398
+ Capabilities.SIMPLEREST_CARDS_JSONPATH;
399
+ Capabilities.SIMPLEREST_CARD_TEXT_JSONPATH;
400
+ Capabilities.SIMPLEREST_CARD_SUBTEXT_JSONPATH;
401
+ Capabilities.SIMPLEREST_CARD_BUTTONS_JSONPATH;
402
+ Capabilities.SIMPLEREST_CARD_ATTACHMENTS_JSONPATH;
392
403
  Capabilities.SIMPLEREST_CONTEXT_JSONPATH;
393
404
  Capabilities.SIMPLEREST_CONTEXT_MERGE_OR_REPLACE;
394
405
  Capabilities.SIMPLEREST_CONVERSATION_ID_TEMPLATE;
@@ -448,6 +459,7 @@ Capabilities.LOGIC_HOOKS;
448
459
  Capabilities.USER_INPUTS;
449
460
  Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT;
450
461
  Capabilities.RATELIMIT_USERSAYS_MINTIME;
462
+ Capabilities.RATELIMIT_BOTTLENECK_FN;
451
463
  Capabilities.SECURITY_ALLOW_UNSAFE;
452
464
  Capabilities.PRECOMPILERS;
453
465
 
@@ -496,7 +508,6 @@ var Defaults$1 = {
496
508
  [Capabilities.SIMPLEREST_METHOD]: 'GET',
497
509
  [Capabilities.SIMPLEREST_IGNORE_EMPTY]: true,
498
510
  [Capabilities.SIMPLEREST_TIMEOUT]: 10000,
499
- [Capabilities.SIMPLEREST_EXTRA_OPTIONS]: {},
500
511
  [Capabilities.SIMPLEREST_STRICT_SSL]: true,
501
512
  [Capabilities.SIMPLEREST_INBOUND_UPDATE_CONTEXT]: true,
502
513
  [Capabilities.SIMPLEREST_CONTEXT_MERGE_OR_REPLACE]: 'MERGE',
@@ -3049,7 +3060,8 @@ class Convo$6 {
3049
3060
  scriptingMemory,
3050
3061
  meMsg,
3051
3062
  transcript,
3052
- transcriptStep
3063
+ transcriptStep,
3064
+ transcriptSteps
3053
3065
  });
3054
3066
  await this.scriptingEvents.onMeStart({
3055
3067
  convo: this,
@@ -3058,7 +3070,8 @@ class Convo$6 {
3058
3070
  scriptingMemory,
3059
3071
  meMsg,
3060
3072
  transcript,
3061
- transcriptStep
3073
+ transcriptStep,
3074
+ transcriptSteps
3062
3075
  });
3063
3076
  await this.scriptingEvents.onMePrepare({
3064
3077
  convo: this,
@@ -3067,7 +3080,8 @@ class Convo$6 {
3067
3080
  scriptingMemory,
3068
3081
  meMsg,
3069
3082
  transcript,
3070
- transcriptStep
3083
+ transcriptStep,
3084
+ transcriptSteps
3071
3085
  });
3072
3086
  await this._checkBotRepliesConsumed(container);
3073
3087
 
@@ -7537,7 +7551,7 @@ var BaseContainer_1 = class BaseContainer {
7537
7551
  this.tempDirectory = tempDirectory;
7538
7552
  this.cleanupTasks = [];
7539
7553
  this.queues = {};
7540
- this.userSaysLimiter = null;
7554
+ this.bottleneck = null;
7541
7555
  }
7542
7556
 
7543
7557
  Validate() {
@@ -7547,18 +7561,33 @@ var BaseContainer_1 = class BaseContainer {
7547
7561
  this.onBotResponseHook = getHook$1(this.caps, this.caps[Capabilities.CUSTOMHOOK_ONBOTRESPONSE]);
7548
7562
  this.onStopHook = getHook$1(this.caps, this.caps[Capabilities.CUSTOMHOOK_ONSTOP]);
7549
7563
  this.onCleanHook = getHook$1(this.caps, this.caps[Capabilities.CUSTOMHOOK_ONCLEAN]);
7550
- return Promise.resolve();
7551
- }
7552
7564
 
7553
- Build() {
7554
- if (this.caps[Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT] || this.caps[Capabilities.RATELIMIT_USERSAYS_MINTIME]) {
7565
+ if (this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN]) {
7566
+ if (lodash.isFunction(this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN])) {
7567
+ this.bottleneck = this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN];
7568
+ debug$7('Validate: Applying userSays rate limits from capability');
7569
+ } else {
7570
+ const limiter = new bottleneck(this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN]);
7571
+
7572
+ this.bottleneck = fn => limiter.schedule(fn);
7573
+
7574
+ debug$7(`Validate: Applying userSays rate limits ${util.inspect(this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN])}`);
7575
+ }
7576
+ } else if (this.caps[Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT] || this.caps[Capabilities.RATELIMIT_USERSAYS_MINTIME]) {
7555
7577
  const opts = {};
7556
7578
  if (this.caps[Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT]) opts.maxConcurrent = this.caps[Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT];
7557
7579
  if (this.caps[Capabilities.RATELIMIT_USERSAYS_MINTIME]) opts.minTime = this.caps[Capabilities.RATELIMIT_USERSAYS_MINTIME];
7558
- this.userSaysLimiter = new bottleneck(opts);
7559
- debug$7(`Build: Applying userSays rate limits ${util.inspect(opts)}`);
7580
+ const limiter = new bottleneck(opts);
7581
+
7582
+ this.bottleneck = fn => limiter.schedule(fn);
7583
+
7584
+ debug$7(`Validate: Applying userSays rate limits ${util.inspect(opts)}`);
7560
7585
  }
7561
7586
 
7587
+ return Promise.resolve();
7588
+ }
7589
+
7590
+ Build() {
7562
7591
  return new Promise((resolve, reject) => {
7563
7592
  this._RunCustomHook('onBuild', this.onBuildHook).then(() => resolve(this)).catch(err => reject(err));
7564
7593
  });
@@ -7584,8 +7613,8 @@ var BaseContainer_1 = class BaseContainer {
7584
7613
  meMsg
7585
7614
  }).then(() => this.UserSaysImpl(meMsg));
7586
7615
 
7587
- if (this.userSaysLimiter) {
7588
- return this.userSaysLimiter.schedule(run);
7616
+ if (this.bottleneck) {
7617
+ return this.bottleneck(run);
7589
7618
  } else {
7590
7619
  return run();
7591
7620
  }
@@ -8073,10 +8102,14 @@ mustache.escape = s => s;
8073
8102
  var SimpleRestContainer_1 = class SimpleRestContainer {
8074
8103
  constructor({
8075
8104
  queueBotSays,
8076
- caps
8105
+ caps,
8106
+ bottleneck
8077
8107
  }) {
8078
8108
  this.queueBotSays = queueBotSays;
8079
8109
  this.caps = Object.assign({}, Defaults, caps);
8110
+
8111
+ this.bottleneck = bottleneck || (fn => fn());
8112
+
8080
8113
  this.processInbound = false;
8081
8114
  this.redisTopic = this.caps[Capabilities.SIMPLEREST_REDIS_TOPIC] || 'SIMPLEREST_INBOUND_SUBSCRIPTION';
8082
8115
 
@@ -8363,31 +8396,82 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8363
8396
  }
8364
8397
 
8365
8398
  for (const jsonPathRoot of jsonPathRoots) {
8366
- const media = [];
8367
- const buttons = [];
8368
- const jsonPathsMedia = getAllCapValues(Capabilities.SIMPLEREST_MEDIA_JSONPATH, this.caps);
8369
- jsonPathsMedia.forEach(jsonPath => {
8370
- const responseMedia = jsonpath.query(jsonPathRoot, jsonPath);
8371
-
8372
- if (responseMedia) {
8373
- (lodash.isArray(responseMedia) ? lodash.flattenDeep(responseMedia) : [responseMedia]).forEach(m => media.push({
8374
- mediaUri: m,
8375
- mimeType: mimeTypes.lookup(m) || 'application/unknown'
8376
- }));
8377
- debug$4(`found response media: ${util.inspect(media)}`);
8399
+ const _retrieveMedia = (jsonPathMediaRoot, jsonPathsMedia) => {
8400
+ const retrievedMedia = [];
8401
+ jsonPathsMedia.forEach(jsonPath => {
8402
+ const responseMedia = jsonpath.query(jsonPathMediaRoot, jsonPath);
8403
+
8404
+ if (responseMedia) {
8405
+ (lodash.isArray(responseMedia) ? lodash.flattenDeep(responseMedia) : [responseMedia]).forEach(m => retrievedMedia.push({
8406
+ mediaUri: m,
8407
+ mimeType: mimeTypes.lookup(m) || 'application/unknown'
8408
+ }));
8409
+ }
8410
+ });
8411
+ return retrievedMedia;
8412
+ };
8413
+
8414
+ const _retrieveButtons = (jsonPathButtonRoot, jsonPathsButtons) => {
8415
+ const retrievedButtons = [];
8416
+ jsonPathsButtons.forEach(jsonPath => {
8417
+ const responseButtons = jsonpath.query(jsonPathButtonRoot, jsonPath);
8418
+
8419
+ if (responseButtons) {
8420
+ (lodash.isArray(responseButtons) ? lodash.flattenDeep(responseButtons) : [responseButtons]).forEach(b => retrievedButtons.push({
8421
+ text: b
8422
+ }));
8423
+ }
8424
+ });
8425
+ return retrievedButtons;
8426
+ };
8427
+
8428
+ const _getCardText = responseCardText => {
8429
+ if (responseCardText) {
8430
+ const texts = lodash.isArray(responseCardText) ? lodash.flattenDeep(responseCardText) : [responseCardText];
8431
+
8432
+ if (texts.length > 1) {
8433
+ debug$4(`more than one text found for card: ${util.inspect(texts)}`);
8434
+ }
8435
+
8436
+ if (texts.length > 0) {
8437
+ return texts[0];
8438
+ }
8378
8439
  }
8379
- });
8380
- const jsonPathsButtons = getAllCapValues(Capabilities.SIMPLEREST_BUTTONS_JSONPATH, this.caps);
8381
- jsonPathsButtons.forEach(jsonPath => {
8382
- const responseButtons = jsonpath.query(jsonPathRoot, jsonPath);
8383
-
8384
- if (responseButtons) {
8385
- (lodash.isArray(responseButtons) ? lodash.flattenDeep(responseButtons) : [responseButtons]).forEach(b => buttons.push({
8386
- text: b
8387
- }));
8388
- debug$4(`found response buttons: ${util.inspect(buttons)}`);
8440
+ };
8441
+
8442
+ const media = _retrieveMedia(jsonPathRoot, getAllCapValues(Capabilities.SIMPLEREST_MEDIA_JSONPATH, this.caps));
8443
+
8444
+ debug$4(`found response media: ${util.inspect(media)}`);
8445
+
8446
+ const buttons = _retrieveButtons(jsonPathRoot, getAllCapValues(Capabilities.SIMPLEREST_BUTTONS_JSONPATH, this.caps));
8447
+
8448
+ debug$4(`found response buttons: ${util.inspect(buttons)}`);
8449
+ const cards = [];
8450
+ const jsonPathsCards = getAllCapValues(Capabilities.SIMPLEREST_CARDS_JSONPATH, this.caps);
8451
+ jsonPathsCards.forEach(jsonPath => {
8452
+ const responseCards = jsonpath.query(jsonPathRoot, jsonPath);
8453
+
8454
+ if (responseCards) {
8455
+ (lodash.isArray(responseCards) ? lodash.flattenDeep(responseCards) : [responseCards]).forEach(c => {
8456
+ const card = {};
8457
+ const jsonPathsCardText = getAllCapValues(Capabilities.SIMPLEREST_CARD_TEXT_JSONPATH, this.caps);
8458
+ jsonPathsCardText.forEach(jsonPath => {
8459
+ card.text = _getCardText(jsonpath.query(c, jsonPath));
8460
+ });
8461
+ const jsonPathsCardSubText = getAllCapValues(Capabilities.SIMPLEREST_CARD_SUBTEXT_JSONPATH, this.caps);
8462
+ jsonPathsCardSubText.forEach(jsonPath => {
8463
+ card.subtext = _getCardText(jsonpath.query(c, jsonPath));
8464
+ });
8465
+ card.buttons = _retrieveButtons(c, getAllCapValues(Capabilities.SIMPLEREST_CARD_BUTTONS_JSONPATH, this.caps));
8466
+ card.media = _retrieveMedia(c, getAllCapValues(Capabilities.SIMPLEREST_CARD_ATTACHMENTS_JSONPATH, this.caps));
8467
+
8468
+ if (lodash.keys(card).length > 0) {
8469
+ cards.push(card);
8470
+ }
8471
+ });
8389
8472
  }
8390
8473
  });
8474
+ debug$4(`found response cards: ${util.inspect(cards)}`);
8391
8475
  let hasMessageText = false;
8392
8476
  const jsonPathsTexts = getAllCapValues(Capabilities.SIMPLEREST_RESPONSE_JSONPATH, this.caps);
8393
8477
 
@@ -8404,7 +8488,8 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8404
8488
  sourceData: body,
8405
8489
  messageText,
8406
8490
  media,
8407
- buttons
8491
+ buttons,
8492
+ cards
8408
8493
  };
8409
8494
  await executeHook(this.caps, this.responseHook, Object.assign({
8410
8495
  botMsg,
@@ -8420,7 +8505,8 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8420
8505
  messageText: '',
8421
8506
  sourceData: body,
8422
8507
  media,
8423
- buttons
8508
+ buttons,
8509
+ cards
8424
8510
  };
8425
8511
  const beforeHookKeys = Object.keys(botMsg);
8426
8512
  await executeHook(this.caps, this.responseHook, Object.assign({
@@ -8429,7 +8515,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8429
8515
  }, this.view));
8430
8516
  const afterHookKeys = Object.keys(botMsg);
8431
8517
 
8432
- if (beforeHookKeys.length !== afterHookKeys.length || !!(botMsg.messageText && botMsg.messageText.length > 0) || botMsg.media.length > 0 || botMsg.buttons.length > 0 || !this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
8518
+ if (beforeHookKeys.length !== afterHookKeys.length || !!(botMsg.messageText && botMsg.messageText.length > 0) || botMsg.media.length > 0 || botMsg.buttons.length > 0 || botMsg.cards.length > 0 || !this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
8433
8519
  result.push(botMsg);
8434
8520
  }
8435
8521
  }
@@ -8615,7 +8701,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8615
8701
  err,
8616
8702
  response,
8617
8703
  body
8618
- } = await new Promise(resolve => {
8704
+ } = await this.bottleneck(() => new Promise(resolve => {
8619
8705
  request(pingConfig, (err, response, body) => {
8620
8706
  resolve({
8621
8707
  err,
@@ -8623,7 +8709,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8623
8709
  body
8624
8710
  });
8625
8711
  });
8626
- });
8712
+ }));
8627
8713
 
8628
8714
  if (err) {
8629
8715
  debug$4(`_waitForUrlResponse error on url check ${pingConfig.uri}: ${err}`);
@@ -9147,6 +9233,7 @@ var PluginConnectorContainer_1 = class PluginConnectorContainer extends BaseCont
9147
9233
  this.pluginInstance = tryLoadPlugin(this.caps[Capabilities.CONTAINERMODE], this.caps[Capabilities.PLUGINMODULEPATH], {
9148
9234
  container: this,
9149
9235
  queueBotSays: msg => this._QueueBotSays(msg),
9236
+ bottleneck: this.bottleneck,
9150
9237
  eventEmitter: this.eventEmitter,
9151
9238
  caps: this.caps,
9152
9239
  sources: this.sources,
@@ -9394,9 +9481,9 @@ var BotDriver_1 = class BotDriver {
9394
9481
 
9395
9482
  Build() {
9396
9483
  debug$1(`Build - Botium Core Version: ${version}`);
9397
- debug$1(`Build - Capabilites: ${util.inspect(this.caps)}`);
9398
- debug$1(`Build - Sources : ${util.inspect(this.sources)}`);
9399
- debug$1(`Build - Envs : ${util.inspect(this.envs)}`);
9484
+ debug$1(`Build - Capabilites: ${JSON.stringify(lodash.pickBy(this.caps, (value, key) => Defaults$1.Capabilities[key] !== value), null, 2)}`);
9485
+ debug$1(`Build - Sources: ${JSON.stringify(lodash.pickBy(this.sources, (value, key) => Defaults$1.Sources[key] !== value), null, 2)}`);
9486
+ debug$1(`Build - Envs: ${JSON.stringify(lodash.pickBy(this.envs, (value, key) => Defaults$1.Envs[key] !== value), null, 2)}`);
9400
9487
  this.eventEmitter.emit(Events.CONTAINER_BUILDING);
9401
9488
  return new Promise((resolve, reject) => {
9402
9489
  let repo = null;