botium-core 1.15.5 → 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 +126 -7
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +126 -7
- package/dist/botium-es.js.map +1 -1
- package/package.json +1 -1
- package/src/Capabilities.js +16 -0
- package/src/containers/plugins/SimpleRestContainer.js +102 -6
- package/test/connectors/simplerest.spec.js +140 -0
package/dist/botium-cjs.js
CHANGED
|
@@ -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.
|
|
80
|
+
var version$1 = "1.15.8";
|
|
81
81
|
var description = "The Selenium for Chatbots";
|
|
82
82
|
var main = "index.js";
|
|
83
83
|
var module$1 = "dist/botium-es.js";
|
|
@@ -315,6 +315,21 @@ var Capabilities = {
|
|
|
315
315
|
SIMPLEREST_INBOUND_ORDER_UNSETTLED_EVENTS_JSONPATH: 'SIMPLEREST_INBOUND_ORDER_UNSETTLED_EVENTS_JSONPATH',
|
|
316
316
|
SIMPLEREST_INBOUND_DEBOUNCE_TIMEOUT: 'SIMPLEREST_INBOUND_DEBOUNCE_TIMEOUT',
|
|
317
317
|
SIMPLEREST_COOKIE_REPLICATION: 'SIMPLEREST_COOKIE_REPLICATION',
|
|
318
|
+
SIMPLEREST_NLP_INTENT_JSONPATH: 'SIMPLEREST_NLP_INTENT_JSONPATH',
|
|
319
|
+
SIMPLEREST_NLP_CONFIDENCE_JSONPATH: 'SIMPLEREST_NLP_CONFIDENCE_JSONPATH',
|
|
320
|
+
SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100: 'SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100',
|
|
321
|
+
SIMPLEREST_NLP_FALLBACK_INTENTS: 'SIMPLEREST_NLP_FALLBACK_INTENTS',
|
|
322
|
+
SIMPLEREST_NLP_LIST_JSONPATH: 'SIMPLEREST_NLP_LIST_JSONPATH',
|
|
323
|
+
SIMPLEREST_NLP_LIST_INTENT_JSONPATH: 'SIMPLEREST_NLP_LIST_INTENT_JSONPATH',
|
|
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',
|
|
318
333
|
// Script Compiler
|
|
319
334
|
SCRIPTING_TXT_EOL: 'SCRIPTING_TXT_EOL',
|
|
320
335
|
// ROW_PER_MESSAGE or QUESTION_ANSWER
|
|
@@ -493,6 +508,14 @@ Capabilities.SIMPLEREST_REDIS_TOPIC;
|
|
|
493
508
|
Capabilities.SIMPLEREST_INBOUND_ORDER_UNSETTLED_EVENTS_JSONPATH;
|
|
494
509
|
Capabilities.SIMPLEREST_INBOUND_DEBOUNCE_TIMEOUT;
|
|
495
510
|
Capabilities.SIMPLEREST_COOKIE_REPLICATION;
|
|
511
|
+
Capabilities.SIMPLEREST_NLP_INTENT_JSONPATH;
|
|
512
|
+
Capabilities.SIMPLEREST_NLP_CONFIDENCE_JSONPATH;
|
|
513
|
+
Capabilities.SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100;
|
|
514
|
+
Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS;
|
|
515
|
+
Capabilities.SIMPLEREST_NLP_LIST_JSONPATH;
|
|
516
|
+
Capabilities.SIMPLEREST_NLP_LIST_INTENT_JSONPATH;
|
|
517
|
+
Capabilities.SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH;
|
|
518
|
+
Capabilities.SIMPLEREST_MESSAGE_LIST_MERGE;
|
|
496
519
|
Capabilities.SCRIPTING_TXT_EOL;
|
|
497
520
|
Capabilities.SCRIPTING_XLSX_MODE;
|
|
498
521
|
Capabilities.SCRIPTING_XLSX_EOL_WRITE;
|
|
@@ -8312,7 +8335,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8312
8335
|
}, true, true), 0);
|
|
8313
8336
|
return;
|
|
8314
8337
|
}
|
|
8315
|
-
|
|
8338
|
+
let result = [];
|
|
8316
8339
|
if (isFromUser) {
|
|
8317
8340
|
const _extractFrom = (root, jsonPaths, acceptFn = null) => {
|
|
8318
8341
|
const result = [];
|
|
@@ -8343,6 +8366,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8343
8366
|
} else {
|
|
8344
8367
|
jsonPathRoots.push(body);
|
|
8345
8368
|
}
|
|
8369
|
+
if (jsonPathRoots.length === 0 && !this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
|
|
8370
|
+
debug$4(`found empty body, and processed because of SIMPLEREST_IGNORE_EMPTY capability: ${util__default["default"].inspect(body)}`);
|
|
8371
|
+
result.push({
|
|
8372
|
+
messageText: '',
|
|
8373
|
+
sourceData: body
|
|
8374
|
+
});
|
|
8375
|
+
}
|
|
8346
8376
|
for (const jsonPathRoot of jsonPathRoots) {
|
|
8347
8377
|
const _retrieveMedia = (jsonPathMediaRoot, jsonPathsMedia) => {
|
|
8348
8378
|
const retrievedMedia = [];
|
|
@@ -8425,6 +8455,75 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8425
8455
|
}
|
|
8426
8456
|
});
|
|
8427
8457
|
debug$4(`found response cards: ${util__default["default"].inspect(cards)}`);
|
|
8458
|
+
let nlp = {
|
|
8459
|
+
intent: {}
|
|
8460
|
+
};
|
|
8461
|
+
const _normalizeIntent = intent => {
|
|
8462
|
+
if ('name' in intent) {
|
|
8463
|
+
if (!intent.name) {
|
|
8464
|
+
intent.name = 'None';
|
|
8465
|
+
}
|
|
8466
|
+
const fallbackIntents = this.caps[Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS];
|
|
8467
|
+
if (fallbackIntents) {
|
|
8468
|
+
intent.incomprehension = this.caps[Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS].includes(intent.name) ? true : undefined;
|
|
8469
|
+
} else {
|
|
8470
|
+
intent.incomprehension = intent.name.toLowerCase() === 'none' ? true : undefined;
|
|
8471
|
+
}
|
|
8472
|
+
}
|
|
8473
|
+
if (!lodash__default["default"].isNil(intent.confidence)) {
|
|
8474
|
+
if (typeof intent.confidence === 'string') {
|
|
8475
|
+
intent.confidence = Number(intent.confidence);
|
|
8476
|
+
}
|
|
8477
|
+
if (lodash__default["default"].isNil(this.caps[Capabilities.SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100]) ? intent.confidence > 1 : this.caps[Capabilities.SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100]) {
|
|
8478
|
+
intent.confidence /= 100;
|
|
8479
|
+
}
|
|
8480
|
+
}
|
|
8481
|
+
return intent;
|
|
8482
|
+
};
|
|
8483
|
+
const jsonPathIntent = this.caps[Capabilities.SIMPLEREST_NLP_INTENT_JSONPATH];
|
|
8484
|
+
if (jsonPathIntent) {
|
|
8485
|
+
const name = jsonpath__default["default"].query(jsonPathRoot, jsonPathIntent);
|
|
8486
|
+
nlp.intent.name = name?.length ? name[0] : null;
|
|
8487
|
+
}
|
|
8488
|
+
const jsonPathConfidence = this.caps[Capabilities.SIMPLEREST_NLP_CONFIDENCE_JSONPATH];
|
|
8489
|
+
if (jsonPathConfidence) {
|
|
8490
|
+
const confidence = jsonpath__default["default"].query(jsonPathRoot, jsonPathConfidence);
|
|
8491
|
+
nlp.intent.confidence = confidence?.length ? confidence[0] : null;
|
|
8492
|
+
}
|
|
8493
|
+
_normalizeIntent(nlp.intent);
|
|
8494
|
+
const jsonPathList = this.caps[Capabilities.SIMPLEREST_NLP_LIST_JSONPATH];
|
|
8495
|
+
const jsonPathListIntent = this.caps[Capabilities.SIMPLEREST_NLP_LIST_INTENT_JSONPATH];
|
|
8496
|
+
const jsonPathListConfidence = this.caps[Capabilities.SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH];
|
|
8497
|
+
if (jsonPathList) {
|
|
8498
|
+
const list = jsonpath__default["default"].query(jsonPathRoot, jsonPathList);
|
|
8499
|
+
if (list?.length) {
|
|
8500
|
+
const intentList = list[0].map(e => {
|
|
8501
|
+
const name = jsonpath__default["default"].query(e, jsonPathListIntent);
|
|
8502
|
+
const res = {
|
|
8503
|
+
name: name?.length ? name[0] : null
|
|
8504
|
+
};
|
|
8505
|
+
if (jsonPathListConfidence) {
|
|
8506
|
+
const confidence = jsonpath__default["default"].query(e, jsonPathListConfidence);
|
|
8507
|
+
res.confidence = confidence?.length ? confidence[0] : null;
|
|
8508
|
+
}
|
|
8509
|
+
_normalizeIntent(res);
|
|
8510
|
+
return res;
|
|
8511
|
+
});
|
|
8512
|
+
if (intentList.length > 0 && !nlp.intent.name) {
|
|
8513
|
+
nlp.intent.name = intentList[0].name;
|
|
8514
|
+
nlp.intent.confidence = intentList[0].confidence;
|
|
8515
|
+
}
|
|
8516
|
+
if (nlp.intent.name === intentList[0].name) {
|
|
8517
|
+
intentList.shift();
|
|
8518
|
+
}
|
|
8519
|
+
nlp.intent.intents = intentList;
|
|
8520
|
+
}
|
|
8521
|
+
}
|
|
8522
|
+
if (Object.keys(nlp.intent).length > 0) {
|
|
8523
|
+
debug$4(`found response nlp: ${util__default["default"].inspect(nlp)}`);
|
|
8524
|
+
} else {
|
|
8525
|
+
nlp = null;
|
|
8526
|
+
}
|
|
8428
8527
|
let hasMessageText = false;
|
|
8429
8528
|
const jsonPathsTexts = getAllCapValues(Capabilities.SIMPLEREST_RESPONSE_JSONPATH, this.caps);
|
|
8430
8529
|
for (const jsonPath of jsonPathsTexts) {
|
|
@@ -8440,7 +8539,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8440
8539
|
messageText,
|
|
8441
8540
|
media,
|
|
8442
8541
|
buttons,
|
|
8443
|
-
|
|
8542
|
+
nlp
|
|
8444
8543
|
};
|
|
8445
8544
|
await executeHook(this.caps, this.responseHook, Object.assign({
|
|
8446
8545
|
botMsg,
|
|
@@ -8456,7 +8555,8 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8456
8555
|
sourceData: body,
|
|
8457
8556
|
media,
|
|
8458
8557
|
buttons,
|
|
8459
|
-
cards
|
|
8558
|
+
cards,
|
|
8559
|
+
nlp
|
|
8460
8560
|
};
|
|
8461
8561
|
const beforeHookKeys = Object.keys(botMsg);
|
|
8462
8562
|
await executeHook(this.caps, this.responseHook, Object.assign({
|
|
@@ -8464,8 +8564,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8464
8564
|
botMsgRoot: jsonPathRoot
|
|
8465
8565
|
}, this.view));
|
|
8466
8566
|
const afterHookKeys = Object.keys(botMsg);
|
|
8467
|
-
if (beforeHookKeys.length !== afterHookKeys.length || !!(botMsg.messageText && botMsg.messageText.length > 0) || botMsg.media.length > 0 || botMsg.buttons.length > 0 || botMsg.cards.length > 0 ||
|
|
8567
|
+
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) {
|
|
8468
8568
|
result.push(botMsg);
|
|
8569
|
+
} else if (!this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
|
|
8570
|
+
debug$4(`found empty message, and processed because of SIMPLEREST_IGNORE_EMPTY capability: ${util__default["default"].inspect(botMsg)}`);
|
|
8571
|
+
result.push(botMsg);
|
|
8572
|
+
} else {
|
|
8573
|
+
debug$4(`found empty message, and ignored because of SIMPLEREST_IGNORE_EMPTY capability: ${util__default["default"].inspect(botMsg)}`);
|
|
8469
8574
|
}
|
|
8470
8575
|
}
|
|
8471
8576
|
}
|
|
@@ -8477,6 +8582,21 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8477
8582
|
messageText: ''
|
|
8478
8583
|
}, true, true), 0);
|
|
8479
8584
|
}
|
|
8585
|
+
if (this.caps[Capabilities.SIMPLEREST_MESSAGE_LIST_MERGE] === 'MERGE_TEXT') {
|
|
8586
|
+
const isTextMsg = msg => msg.messageText && (!msg.media || msg.media.length === 0) && (!msg.buttons || msg.buttons.length === 0) && (!msg.cards || msg.cards.length === 0);
|
|
8587
|
+
result = result.reduce((acc, currentMsg) => {
|
|
8588
|
+
if (acc.length > 0) {
|
|
8589
|
+
const last = acc[acc.length - 1];
|
|
8590
|
+
if (isTextMsg(last)) {
|
|
8591
|
+
currentMsg.messageText = [last.messageText, currentMsg.messageText].filter(t => t).join('\n');
|
|
8592
|
+
acc[acc.length - 1] = currentMsg;
|
|
8593
|
+
return acc;
|
|
8594
|
+
}
|
|
8595
|
+
}
|
|
8596
|
+
acc.push(currentMsg);
|
|
8597
|
+
return acc;
|
|
8598
|
+
}, []);
|
|
8599
|
+
}
|
|
8480
8600
|
return result;
|
|
8481
8601
|
}
|
|
8482
8602
|
_doRequest(msg, isFromUser, updateContext) {
|
|
@@ -8489,8 +8609,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8489
8609
|
fetch(requestOptions.uri, requestOptions).then(async bodyRaw => {
|
|
8490
8610
|
let body;
|
|
8491
8611
|
try {
|
|
8492
|
-
|
|
8493
|
-
if (contentType && contentType.includes('application/json')) {
|
|
8612
|
+
if (bodyRaw?.headers?.get('content-type') && bodyRaw.headers.get('content-type').includes('application/json')) {
|
|
8494
8613
|
try {
|
|
8495
8614
|
body = await bodyRaw.json();
|
|
8496
8615
|
} catch (err) {
|