botium-core 1.15.6 → 1.15.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/dist/botium-cjs.js +40 -5
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +40 -5
- package/dist/botium-es.js.map +1 -1
- package/package.json +1 -1
- package/src/Capabilities.js +9 -0
- package/src/containers/plugins/SimpleRestContainer.js +30 -4
- package/test/connectors/simplerest.spec.js +78 -0
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.
|
|
38
|
+
var version$1 = "1.15.8";
|
|
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;
|
|
@@ -8284,7 +8293,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8284
8293
|
}, true, true), 0);
|
|
8285
8294
|
return;
|
|
8286
8295
|
}
|
|
8287
|
-
|
|
8296
|
+
let result = [];
|
|
8288
8297
|
if (isFromUser) {
|
|
8289
8298
|
const _extractFrom = (root, jsonPaths, acceptFn = null) => {
|
|
8290
8299
|
const result = [];
|
|
@@ -8315,6 +8324,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8315
8324
|
} else {
|
|
8316
8325
|
jsonPathRoots.push(body);
|
|
8317
8326
|
}
|
|
8327
|
+
if (jsonPathRoots.length === 0 && !this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
|
|
8328
|
+
debug$4(`found empty body, and processed because of SIMPLEREST_IGNORE_EMPTY capability: ${util.inspect(body)}`);
|
|
8329
|
+
result.push({
|
|
8330
|
+
messageText: '',
|
|
8331
|
+
sourceData: body
|
|
8332
|
+
});
|
|
8333
|
+
}
|
|
8318
8334
|
for (const jsonPathRoot of jsonPathRoots) {
|
|
8319
8335
|
const _retrieveMedia = (jsonPathMediaRoot, jsonPathsMedia) => {
|
|
8320
8336
|
const retrievedMedia = [];
|
|
@@ -8506,8 +8522,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8506
8522
|
botMsgRoot: jsonPathRoot
|
|
8507
8523
|
}, this.view));
|
|
8508
8524
|
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
|
|
8525
|
+
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
8526
|
result.push(botMsg);
|
|
8527
|
+
} else if (!this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
|
|
8528
|
+
debug$4(`found empty message, and processed because of SIMPLEREST_IGNORE_EMPTY capability: ${util.inspect(botMsg)}`);
|
|
8529
|
+
result.push(botMsg);
|
|
8530
|
+
} else {
|
|
8531
|
+
debug$4(`found empty message, and ignored because of SIMPLEREST_IGNORE_EMPTY capability: ${util.inspect(botMsg)}`);
|
|
8511
8532
|
}
|
|
8512
8533
|
}
|
|
8513
8534
|
}
|
|
@@ -8519,6 +8540,21 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8519
8540
|
messageText: ''
|
|
8520
8541
|
}, true, true), 0);
|
|
8521
8542
|
}
|
|
8543
|
+
if (this.caps[Capabilities.SIMPLEREST_MESSAGE_LIST_MERGE] === 'MERGE_TEXT') {
|
|
8544
|
+
const isTextMsg = msg => msg.messageText && (!msg.media || msg.media.length === 0) && (!msg.buttons || msg.buttons.length === 0) && (!msg.cards || msg.cards.length === 0);
|
|
8545
|
+
result = result.reduce((acc, currentMsg) => {
|
|
8546
|
+
if (acc.length > 0) {
|
|
8547
|
+
const last = acc[acc.length - 1];
|
|
8548
|
+
if (isTextMsg(last)) {
|
|
8549
|
+
currentMsg.messageText = [last.messageText, currentMsg.messageText].filter(t => t).join('\n');
|
|
8550
|
+
acc[acc.length - 1] = currentMsg;
|
|
8551
|
+
return acc;
|
|
8552
|
+
}
|
|
8553
|
+
}
|
|
8554
|
+
acc.push(currentMsg);
|
|
8555
|
+
return acc;
|
|
8556
|
+
}, []);
|
|
8557
|
+
}
|
|
8522
8558
|
return result;
|
|
8523
8559
|
}
|
|
8524
8560
|
_doRequest(msg, isFromUser, updateContext) {
|
|
@@ -8531,8 +8567,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8531
8567
|
fetch(requestOptions.uri, requestOptions).then(async bodyRaw => {
|
|
8532
8568
|
let body;
|
|
8533
8569
|
try {
|
|
8534
|
-
|
|
8535
|
-
if (contentType && contentType.includes('application/json')) {
|
|
8570
|
+
if (bodyRaw?.headers?.get('content-type') && bodyRaw.headers.get('content-type').includes('application/json')) {
|
|
8536
8571
|
try {
|
|
8537
8572
|
body = await bodyRaw.json();
|
|
8538
8573
|
} catch (err) {
|