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.
package/dist/botium-es.js CHANGED
@@ -35,7 +35,7 @@ import express from 'express';
35
35
  import bodyParser from 'body-parser';
36
36
 
37
37
  var name = "botium-core";
38
- var version$1 = "1.15.6";
38
+ var version$1 = "1.15.9";
39
39
  var description = "The Selenium for Chatbots";
40
40
  var main = "index.js";
41
41
  var module = "dist/botium-es.js";
@@ -280,6 +280,14 @@ var Capabilities = {
280
280
  SIMPLEREST_NLP_LIST_JSONPATH: 'SIMPLEREST_NLP_LIST_JSONPATH',
281
281
  SIMPLEREST_NLP_LIST_INTENT_JSONPATH: 'SIMPLEREST_NLP_LIST_INTENT_JSONPATH',
282
282
  SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH: 'SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH',
283
+ /**
284
+ * Single response can contain a list of messages. This capability defines how to merge the list into a single message.
285
+ * It can be 'OFF' (default), 'MERGE_TEXT'
286
+ * @type {string}
287
+ * @default 'OFF'
288
+ * @description Merge message list into single message
289
+ */
290
+ SIMPLEREST_MESSAGE_LIST_MERGE: 'SIMPLEREST_MESSAGE_LIST_MERGE',
283
291
  // Script Compiler
284
292
  SCRIPTING_TXT_EOL: 'SCRIPTING_TXT_EOL',
285
293
  // ROW_PER_MESSAGE or QUESTION_ANSWER
@@ -465,6 +473,7 @@ Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS;
465
473
  Capabilities.SIMPLEREST_NLP_LIST_JSONPATH;
466
474
  Capabilities.SIMPLEREST_NLP_LIST_INTENT_JSONPATH;
467
475
  Capabilities.SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH;
476
+ Capabilities.SIMPLEREST_MESSAGE_LIST_MERGE;
468
477
  Capabilities.SCRIPTING_TXT_EOL;
469
478
  Capabilities.SCRIPTING_XLSX_MODE;
470
479
  Capabilities.SCRIPTING_XLSX_EOL_WRITE;
@@ -6046,12 +6055,18 @@ var ScriptingProvider_1 = class ScriptingProvider {
6046
6055
  if (hookType !== 'onMeStart' && hookType !== 'onMePrepare' && hookType !== 'onMeEnd' && hookType !== 'onBotStart' && hookType !== 'onBotPrepare' && hookType !== 'onBotEnd' && hookType !== 'onConvoBegin' && hookType !== 'onConvoEnd') {
6047
6056
  throw Error(`Unknown hookType ${hookType}`);
6048
6057
  }
6049
- const localHooks = (logicHooks || []).filter(l => this.logicHooks[l.name][hookType]);
6058
+ let localHooks = (logicHooks || []).filter(l => this.logicHooks[l.name][hookType]);
6059
+ // Scripting memory file are injected via SET_SCRIPTING_MEMORY in the BEGIN step
6060
+ // But there might be other logic hooks that need the scripting memory variables
6061
+ // Order is important (SET_SCRIPTING_MEMORY in begin can be because the user added it,
6062
+ // or because the scripting memory file added it. User one has to be the last one.
6063
+ localHooks = [...localHooks.filter(l => l.name === 'SET_SCRIPTING_MEMORY'), ...localHooks.filter(l => l.name !== 'SET_SCRIPTING_MEMORY')];
6050
6064
  const convoStepPromises = localHooks.map(l => p(this.retryHelperLogicHook, () => this.logicHooks[l.name][hookType]({
6051
6065
  convo,
6052
6066
  convoStep,
6053
6067
  scriptingMemory,
6054
6068
  container,
6069
+ // Do this more sensitve for SET_SCRIPTING_MEMORY? It can have scripting variables in the args
6055
6070
  args: ScriptingMemory.applyToArgs(l.args, scriptingMemory, container.caps, rest.botMsg),
6056
6071
  isGlobal: false,
6057
6072
  ...rest
@@ -8284,7 +8299,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8284
8299
  }, true, true), 0);
8285
8300
  return;
8286
8301
  }
8287
- const result = [];
8302
+ let result = [];
8288
8303
  if (isFromUser) {
8289
8304
  const _extractFrom = (root, jsonPaths, acceptFn = null) => {
8290
8305
  const result = [];
@@ -8315,6 +8330,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8315
8330
  } else {
8316
8331
  jsonPathRoots.push(body);
8317
8332
  }
8333
+ if (jsonPathRoots.length === 0 && !this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
8334
+ debug$4(`found empty body, and processed because of SIMPLEREST_IGNORE_EMPTY capability: ${util.inspect(body)}`);
8335
+ result.push({
8336
+ messageText: '',
8337
+ sourceData: body
8338
+ });
8339
+ }
8318
8340
  for (const jsonPathRoot of jsonPathRoots) {
8319
8341
  const _retrieveMedia = (jsonPathMediaRoot, jsonPathsMedia) => {
8320
8342
  const retrievedMedia = [];
@@ -8506,8 +8528,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8506
8528
  botMsgRoot: jsonPathRoot
8507
8529
  }, this.view));
8508
8530
  const afterHookKeys = Object.keys(botMsg);
8509
- 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]) {
8531
+ 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) {
8510
8532
  result.push(botMsg);
8533
+ } else if (!this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
8534
+ debug$4(`found empty message, and processed because of SIMPLEREST_IGNORE_EMPTY capability: ${util.inspect(botMsg)}`);
8535
+ result.push(botMsg);
8536
+ } else {
8537
+ debug$4(`found empty message, and ignored because of SIMPLEREST_IGNORE_EMPTY capability: ${util.inspect(botMsg)}`);
8511
8538
  }
8512
8539
  }
8513
8540
  }
@@ -8519,6 +8546,21 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8519
8546
  messageText: ''
8520
8547
  }, true, true), 0);
8521
8548
  }
8549
+ if (this.caps[Capabilities.SIMPLEREST_MESSAGE_LIST_MERGE] === 'MERGE_TEXT') {
8550
+ const isTextMsg = msg => msg.messageText && (!msg.media || msg.media.length === 0) && (!msg.buttons || msg.buttons.length === 0) && (!msg.cards || msg.cards.length === 0);
8551
+ result = result.reduce((acc, currentMsg) => {
8552
+ if (acc.length > 0) {
8553
+ const last = acc[acc.length - 1];
8554
+ if (isTextMsg(last)) {
8555
+ currentMsg.messageText = [last.messageText, currentMsg.messageText].filter(t => t).join('\n');
8556
+ acc[acc.length - 1] = currentMsg;
8557
+ return acc;
8558
+ }
8559
+ }
8560
+ acc.push(currentMsg);
8561
+ return acc;
8562
+ }, []);
8563
+ }
8522
8564
  return result;
8523
8565
  }
8524
8566
  _doRequest(msg, isFromUser, updateContext) {
@@ -8531,8 +8573,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8531
8573
  fetch(requestOptions.uri, requestOptions).then(async bodyRaw => {
8532
8574
  let body;
8533
8575
  try {
8534
- const contentType = bodyRaw.headers.get('content-type');
8535
- if (contentType && contentType.includes('application/json')) {
8576
+ if (bodyRaw?.headers?.get('content-type') && bodyRaw.headers.get('content-type').includes('application/json')) {
8536
8577
  try {
8537
8578
  body = await bodyRaw.json();
8538
8579
  } catch (err) {
@@ -9494,8 +9535,8 @@ var BotDriver_1 = class BotDriver {
9494
9535
  if (lodash.isString(newCaps[capKey])) {
9495
9536
  try {
9496
9537
  caps[capKey] = JSON.parse(newCaps[capKey]);
9497
- if (lodash.isFinite(caps[capKey])) {
9498
- caps[capKey] = caps[capKey].toString();
9538
+ if (lodash.isFinite(Number(newCaps[capKey]))) {
9539
+ caps[capKey] = newCaps[capKey].toString();
9499
9540
  }
9500
9541
  } catch (err) {
9501
9542
  caps[capKey] = newCaps[capKey];