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-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";
|
|
@@ -273,6 +273,21 @@ var Capabilities = {
|
|
|
273
273
|
SIMPLEREST_INBOUND_ORDER_UNSETTLED_EVENTS_JSONPATH: 'SIMPLEREST_INBOUND_ORDER_UNSETTLED_EVENTS_JSONPATH',
|
|
274
274
|
SIMPLEREST_INBOUND_DEBOUNCE_TIMEOUT: 'SIMPLEREST_INBOUND_DEBOUNCE_TIMEOUT',
|
|
275
275
|
SIMPLEREST_COOKIE_REPLICATION: 'SIMPLEREST_COOKIE_REPLICATION',
|
|
276
|
+
SIMPLEREST_NLP_INTENT_JSONPATH: 'SIMPLEREST_NLP_INTENT_JSONPATH',
|
|
277
|
+
SIMPLEREST_NLP_CONFIDENCE_JSONPATH: 'SIMPLEREST_NLP_CONFIDENCE_JSONPATH',
|
|
278
|
+
SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100: 'SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100',
|
|
279
|
+
SIMPLEREST_NLP_FALLBACK_INTENTS: 'SIMPLEREST_NLP_FALLBACK_INTENTS',
|
|
280
|
+
SIMPLEREST_NLP_LIST_JSONPATH: 'SIMPLEREST_NLP_LIST_JSONPATH',
|
|
281
|
+
SIMPLEREST_NLP_LIST_INTENT_JSONPATH: 'SIMPLEREST_NLP_LIST_INTENT_JSONPATH',
|
|
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',
|
|
276
291
|
// Script Compiler
|
|
277
292
|
SCRIPTING_TXT_EOL: 'SCRIPTING_TXT_EOL',
|
|
278
293
|
// ROW_PER_MESSAGE or QUESTION_ANSWER
|
|
@@ -451,6 +466,14 @@ Capabilities.SIMPLEREST_REDIS_TOPIC;
|
|
|
451
466
|
Capabilities.SIMPLEREST_INBOUND_ORDER_UNSETTLED_EVENTS_JSONPATH;
|
|
452
467
|
Capabilities.SIMPLEREST_INBOUND_DEBOUNCE_TIMEOUT;
|
|
453
468
|
Capabilities.SIMPLEREST_COOKIE_REPLICATION;
|
|
469
|
+
Capabilities.SIMPLEREST_NLP_INTENT_JSONPATH;
|
|
470
|
+
Capabilities.SIMPLEREST_NLP_CONFIDENCE_JSONPATH;
|
|
471
|
+
Capabilities.SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100;
|
|
472
|
+
Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS;
|
|
473
|
+
Capabilities.SIMPLEREST_NLP_LIST_JSONPATH;
|
|
474
|
+
Capabilities.SIMPLEREST_NLP_LIST_INTENT_JSONPATH;
|
|
475
|
+
Capabilities.SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH;
|
|
476
|
+
Capabilities.SIMPLEREST_MESSAGE_LIST_MERGE;
|
|
454
477
|
Capabilities.SCRIPTING_TXT_EOL;
|
|
455
478
|
Capabilities.SCRIPTING_XLSX_MODE;
|
|
456
479
|
Capabilities.SCRIPTING_XLSX_EOL_WRITE;
|
|
@@ -8270,7 +8293,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8270
8293
|
}, true, true), 0);
|
|
8271
8294
|
return;
|
|
8272
8295
|
}
|
|
8273
|
-
|
|
8296
|
+
let result = [];
|
|
8274
8297
|
if (isFromUser) {
|
|
8275
8298
|
const _extractFrom = (root, jsonPaths, acceptFn = null) => {
|
|
8276
8299
|
const result = [];
|
|
@@ -8301,6 +8324,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8301
8324
|
} else {
|
|
8302
8325
|
jsonPathRoots.push(body);
|
|
8303
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
|
+
}
|
|
8304
8334
|
for (const jsonPathRoot of jsonPathRoots) {
|
|
8305
8335
|
const _retrieveMedia = (jsonPathMediaRoot, jsonPathsMedia) => {
|
|
8306
8336
|
const retrievedMedia = [];
|
|
@@ -8383,6 +8413,75 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8383
8413
|
}
|
|
8384
8414
|
});
|
|
8385
8415
|
debug$4(`found response cards: ${util.inspect(cards)}`);
|
|
8416
|
+
let nlp = {
|
|
8417
|
+
intent: {}
|
|
8418
|
+
};
|
|
8419
|
+
const _normalizeIntent = intent => {
|
|
8420
|
+
if ('name' in intent) {
|
|
8421
|
+
if (!intent.name) {
|
|
8422
|
+
intent.name = 'None';
|
|
8423
|
+
}
|
|
8424
|
+
const fallbackIntents = this.caps[Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS];
|
|
8425
|
+
if (fallbackIntents) {
|
|
8426
|
+
intent.incomprehension = this.caps[Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS].includes(intent.name) ? true : undefined;
|
|
8427
|
+
} else {
|
|
8428
|
+
intent.incomprehension = intent.name.toLowerCase() === 'none' ? true : undefined;
|
|
8429
|
+
}
|
|
8430
|
+
}
|
|
8431
|
+
if (!lodash.isNil(intent.confidence)) {
|
|
8432
|
+
if (typeof intent.confidence === 'string') {
|
|
8433
|
+
intent.confidence = Number(intent.confidence);
|
|
8434
|
+
}
|
|
8435
|
+
if (lodash.isNil(this.caps[Capabilities.SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100]) ? intent.confidence > 1 : this.caps[Capabilities.SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100]) {
|
|
8436
|
+
intent.confidence /= 100;
|
|
8437
|
+
}
|
|
8438
|
+
}
|
|
8439
|
+
return intent;
|
|
8440
|
+
};
|
|
8441
|
+
const jsonPathIntent = this.caps[Capabilities.SIMPLEREST_NLP_INTENT_JSONPATH];
|
|
8442
|
+
if (jsonPathIntent) {
|
|
8443
|
+
const name = jsonpath.query(jsonPathRoot, jsonPathIntent);
|
|
8444
|
+
nlp.intent.name = name?.length ? name[0] : null;
|
|
8445
|
+
}
|
|
8446
|
+
const jsonPathConfidence = this.caps[Capabilities.SIMPLEREST_NLP_CONFIDENCE_JSONPATH];
|
|
8447
|
+
if (jsonPathConfidence) {
|
|
8448
|
+
const confidence = jsonpath.query(jsonPathRoot, jsonPathConfidence);
|
|
8449
|
+
nlp.intent.confidence = confidence?.length ? confidence[0] : null;
|
|
8450
|
+
}
|
|
8451
|
+
_normalizeIntent(nlp.intent);
|
|
8452
|
+
const jsonPathList = this.caps[Capabilities.SIMPLEREST_NLP_LIST_JSONPATH];
|
|
8453
|
+
const jsonPathListIntent = this.caps[Capabilities.SIMPLEREST_NLP_LIST_INTENT_JSONPATH];
|
|
8454
|
+
const jsonPathListConfidence = this.caps[Capabilities.SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH];
|
|
8455
|
+
if (jsonPathList) {
|
|
8456
|
+
const list = jsonpath.query(jsonPathRoot, jsonPathList);
|
|
8457
|
+
if (list?.length) {
|
|
8458
|
+
const intentList = list[0].map(e => {
|
|
8459
|
+
const name = jsonpath.query(e, jsonPathListIntent);
|
|
8460
|
+
const res = {
|
|
8461
|
+
name: name?.length ? name[0] : null
|
|
8462
|
+
};
|
|
8463
|
+
if (jsonPathListConfidence) {
|
|
8464
|
+
const confidence = jsonpath.query(e, jsonPathListConfidence);
|
|
8465
|
+
res.confidence = confidence?.length ? confidence[0] : null;
|
|
8466
|
+
}
|
|
8467
|
+
_normalizeIntent(res);
|
|
8468
|
+
return res;
|
|
8469
|
+
});
|
|
8470
|
+
if (intentList.length > 0 && !nlp.intent.name) {
|
|
8471
|
+
nlp.intent.name = intentList[0].name;
|
|
8472
|
+
nlp.intent.confidence = intentList[0].confidence;
|
|
8473
|
+
}
|
|
8474
|
+
if (nlp.intent.name === intentList[0].name) {
|
|
8475
|
+
intentList.shift();
|
|
8476
|
+
}
|
|
8477
|
+
nlp.intent.intents = intentList;
|
|
8478
|
+
}
|
|
8479
|
+
}
|
|
8480
|
+
if (Object.keys(nlp.intent).length > 0) {
|
|
8481
|
+
debug$4(`found response nlp: ${util.inspect(nlp)}`);
|
|
8482
|
+
} else {
|
|
8483
|
+
nlp = null;
|
|
8484
|
+
}
|
|
8386
8485
|
let hasMessageText = false;
|
|
8387
8486
|
const jsonPathsTexts = getAllCapValues(Capabilities.SIMPLEREST_RESPONSE_JSONPATH, this.caps);
|
|
8388
8487
|
for (const jsonPath of jsonPathsTexts) {
|
|
@@ -8398,7 +8497,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8398
8497
|
messageText,
|
|
8399
8498
|
media,
|
|
8400
8499
|
buttons,
|
|
8401
|
-
|
|
8500
|
+
nlp
|
|
8402
8501
|
};
|
|
8403
8502
|
await executeHook(this.caps, this.responseHook, Object.assign({
|
|
8404
8503
|
botMsg,
|
|
@@ -8414,7 +8513,8 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8414
8513
|
sourceData: body,
|
|
8415
8514
|
media,
|
|
8416
8515
|
buttons,
|
|
8417
|
-
cards
|
|
8516
|
+
cards,
|
|
8517
|
+
nlp
|
|
8418
8518
|
};
|
|
8419
8519
|
const beforeHookKeys = Object.keys(botMsg);
|
|
8420
8520
|
await executeHook(this.caps, this.responseHook, Object.assign({
|
|
@@ -8422,8 +8522,13 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8422
8522
|
botMsgRoot: jsonPathRoot
|
|
8423
8523
|
}, this.view));
|
|
8424
8524
|
const afterHookKeys = Object.keys(botMsg);
|
|
8425
|
-
if (beforeHookKeys.length !== afterHookKeys.length || !!(botMsg.messageText && botMsg.messageText.length > 0) || botMsg.media.length > 0 || botMsg.buttons.length > 0 || botMsg.cards.length > 0 ||
|
|
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) {
|
|
8426
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)}`);
|
|
8427
8532
|
}
|
|
8428
8533
|
}
|
|
8429
8534
|
}
|
|
@@ -8435,6 +8540,21 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8435
8540
|
messageText: ''
|
|
8436
8541
|
}, true, true), 0);
|
|
8437
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
|
+
}
|
|
8438
8558
|
return result;
|
|
8439
8559
|
}
|
|
8440
8560
|
_doRequest(msg, isFromUser, updateContext) {
|
|
@@ -8447,8 +8567,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8447
8567
|
fetch(requestOptions.uri, requestOptions).then(async bodyRaw => {
|
|
8448
8568
|
let body;
|
|
8449
8569
|
try {
|
|
8450
|
-
|
|
8451
|
-
if (contentType && contentType.includes('application/json')) {
|
|
8570
|
+
if (bodyRaw?.headers?.get('content-type') && bodyRaw.headers.get('content-type').includes('application/json')) {
|
|
8452
8571
|
try {
|
|
8453
8572
|
body = await bodyRaw.json();
|
|
8454
8573
|
} catch (err) {
|