botium-core 1.15.6 → 1.15.9

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.
@@ -77,7 +77,7 @@ var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
77
77
  var bodyParser__default = /*#__PURE__*/_interopDefaultLegacy(bodyParser);
78
78
 
79
79
  var name = "botium-core";
80
- var version$1 = "1.15.6";
80
+ var version$1 = "1.15.9";
81
81
  var description = "The Selenium for Chatbots";
82
82
  var main = "index.js";
83
83
  var module$1 = "dist/botium-es.js";
@@ -322,6 +322,14 @@ var Capabilities = {
322
322
  SIMPLEREST_NLP_LIST_JSONPATH: 'SIMPLEREST_NLP_LIST_JSONPATH',
323
323
  SIMPLEREST_NLP_LIST_INTENT_JSONPATH: 'SIMPLEREST_NLP_LIST_INTENT_JSONPATH',
324
324
  SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH: 'SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH',
325
+ /**
326
+ * Single response can contain a list of messages. This capability defines how to merge the list into a single message.
327
+ * It can be 'OFF' (default), 'MERGE_TEXT'
328
+ * @type {string}
329
+ * @default 'OFF'
330
+ * @description Merge message list into single message
331
+ */
332
+ SIMPLEREST_MESSAGE_LIST_MERGE: 'SIMPLEREST_MESSAGE_LIST_MERGE',
325
333
  // Script Compiler
326
334
  SCRIPTING_TXT_EOL: 'SCRIPTING_TXT_EOL',
327
335
  // ROW_PER_MESSAGE or QUESTION_ANSWER
@@ -507,6 +515,7 @@ Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS;
507
515
  Capabilities.SIMPLEREST_NLP_LIST_JSONPATH;
508
516
  Capabilities.SIMPLEREST_NLP_LIST_INTENT_JSONPATH;
509
517
  Capabilities.SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH;
518
+ Capabilities.SIMPLEREST_MESSAGE_LIST_MERGE;
510
519
  Capabilities.SCRIPTING_TXT_EOL;
511
520
  Capabilities.SCRIPTING_XLSX_MODE;
512
521
  Capabilities.SCRIPTING_XLSX_EOL_WRITE;
@@ -6088,12 +6097,18 @@ var ScriptingProvider_1 = class ScriptingProvider {
6088
6097
  if (hookType !== 'onMeStart' && hookType !== 'onMePrepare' && hookType !== 'onMeEnd' && hookType !== 'onBotStart' && hookType !== 'onBotPrepare' && hookType !== 'onBotEnd' && hookType !== 'onConvoBegin' && hookType !== 'onConvoEnd') {
6089
6098
  throw Error(`Unknown hookType ${hookType}`);
6090
6099
  }
6091
- const localHooks = (logicHooks || []).filter(l => this.logicHooks[l.name][hookType]);
6100
+ let localHooks = (logicHooks || []).filter(l => this.logicHooks[l.name][hookType]);
6101
+ // Scripting memory file are injected via SET_SCRIPTING_MEMORY in the BEGIN step
6102
+ // But there might be other logic hooks that need the scripting memory variables
6103
+ // Order is important (SET_SCRIPTING_MEMORY in begin can be because the user added it,
6104
+ // or because the scripting memory file added it. User one has to be the last one.
6105
+ localHooks = [...localHooks.filter(l => l.name === 'SET_SCRIPTING_MEMORY'), ...localHooks.filter(l => l.name !== 'SET_SCRIPTING_MEMORY')];
6092
6106
  const convoStepPromises = localHooks.map(l => p(this.retryHelperLogicHook, () => this.logicHooks[l.name][hookType]({
6093
6107
  convo,
6094
6108
  convoStep,
6095
6109
  scriptingMemory,
6096
6110
  container,
6111
+ // Do this more sensitve for SET_SCRIPTING_MEMORY? It can have scripting variables in the args
6097
6112
  args: ScriptingMemory.applyToArgs(l.args, scriptingMemory, container.caps, rest.botMsg),
6098
6113
  isGlobal: false,
6099
6114
  ...rest
@@ -8326,7 +8341,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8326
8341
  }, true, true), 0);
8327
8342
  return;
8328
8343
  }
8329
- const result = [];
8344
+ let result = [];
8330
8345
  if (isFromUser) {
8331
8346
  const _extractFrom = (root, jsonPaths, acceptFn = null) => {
8332
8347
  const result = [];
@@ -8357,6 +8372,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8357
8372
  } else {
8358
8373
  jsonPathRoots.push(body);
8359
8374
  }
8375
+ if (jsonPathRoots.length === 0 && !this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
8376
+ debug$4(`found empty body, and processed because of SIMPLEREST_IGNORE_EMPTY capability: ${util__default["default"].inspect(body)}`);
8377
+ result.push({
8378
+ messageText: '',
8379
+ sourceData: body
8380
+ });
8381
+ }
8360
8382
  for (const jsonPathRoot of jsonPathRoots) {
8361
8383
  const _retrieveMedia = (jsonPathMediaRoot, jsonPathsMedia) => {
8362
8384
  const retrievedMedia = [];
@@ -8548,8 +8570,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8548
8570
  botMsgRoot: jsonPathRoot
8549
8571
  }, this.view));
8550
8572
  const afterHookKeys = Object.keys(botMsg);
8551
- if (beforeHookKeys.length !== afterHookKeys.length || !!(botMsg.messageText && botMsg.messageText.length > 0) || botMsg.media.length > 0 || botMsg.buttons.length > 0 || botMsg.cards.length > 0 || botMsg.nlp || !this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
8573
+ if (beforeHookKeys.length !== afterHookKeys.length || !!(botMsg.messageText && botMsg.messageText.length > 0) || botMsg.media.length > 0 || botMsg.buttons.length > 0 || botMsg.cards.length > 0 || botMsg.nlp) {
8552
8574
  result.push(botMsg);
8575
+ } else if (!this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
8576
+ debug$4(`found empty message, and processed because of SIMPLEREST_IGNORE_EMPTY capability: ${util__default["default"].inspect(botMsg)}`);
8577
+ result.push(botMsg);
8578
+ } else {
8579
+ debug$4(`found empty message, and ignored because of SIMPLEREST_IGNORE_EMPTY capability: ${util__default["default"].inspect(botMsg)}`);
8553
8580
  }
8554
8581
  }
8555
8582
  }
@@ -8561,6 +8588,21 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8561
8588
  messageText: ''
8562
8589
  }, true, true), 0);
8563
8590
  }
8591
+ if (this.caps[Capabilities.SIMPLEREST_MESSAGE_LIST_MERGE] === 'MERGE_TEXT') {
8592
+ const isTextMsg = msg => msg.messageText && (!msg.media || msg.media.length === 0) && (!msg.buttons || msg.buttons.length === 0) && (!msg.cards || msg.cards.length === 0);
8593
+ result = result.reduce((acc, currentMsg) => {
8594
+ if (acc.length > 0) {
8595
+ const last = acc[acc.length - 1];
8596
+ if (isTextMsg(last)) {
8597
+ currentMsg.messageText = [last.messageText, currentMsg.messageText].filter(t => t).join('\n');
8598
+ acc[acc.length - 1] = currentMsg;
8599
+ return acc;
8600
+ }
8601
+ }
8602
+ acc.push(currentMsg);
8603
+ return acc;
8604
+ }, []);
8605
+ }
8564
8606
  return result;
8565
8607
  }
8566
8608
  _doRequest(msg, isFromUser, updateContext) {
@@ -8573,8 +8615,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8573
8615
  fetch(requestOptions.uri, requestOptions).then(async bodyRaw => {
8574
8616
  let body;
8575
8617
  try {
8576
- const contentType = bodyRaw.headers.get('content-type');
8577
- if (contentType && contentType.includes('application/json')) {
8618
+ if (bodyRaw?.headers?.get('content-type') && bodyRaw.headers.get('content-type').includes('application/json')) {
8578
8619
  try {
8579
8620
  body = await bodyRaw.json();
8580
8621
  } catch (err) {
@@ -9536,8 +9577,8 @@ var BotDriver_1 = class BotDriver {
9536
9577
  if (lodash__default["default"].isString(newCaps[capKey])) {
9537
9578
  try {
9538
9579
  caps[capKey] = JSON.parse(newCaps[capKey]);
9539
- if (lodash__default["default"].isFinite(caps[capKey])) {
9540
- caps[capKey] = caps[capKey].toString();
9580
+ if (lodash__default["default"].isFinite(Number(newCaps[capKey]))) {
9581
+ caps[capKey] = newCaps[capKey].toString();
9541
9582
  }
9542
9583
  } catch (err) {
9543
9584
  caps[capKey] = newCaps[capKey];