botium-core 1.15.4 → 1.15.6

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.4";
80
+ var version$1 = "1.15.6";
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,13 @@ 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',
318
325
  // Script Compiler
319
326
  SCRIPTING_TXT_EOL: 'SCRIPTING_TXT_EOL',
320
327
  // ROW_PER_MESSAGE or QUESTION_ANSWER
@@ -493,6 +500,13 @@ Capabilities.SIMPLEREST_REDIS_TOPIC;
493
500
  Capabilities.SIMPLEREST_INBOUND_ORDER_UNSETTLED_EVENTS_JSONPATH;
494
501
  Capabilities.SIMPLEREST_INBOUND_DEBOUNCE_TIMEOUT;
495
502
  Capabilities.SIMPLEREST_COOKIE_REPLICATION;
503
+ Capabilities.SIMPLEREST_NLP_INTENT_JSONPATH;
504
+ Capabilities.SIMPLEREST_NLP_CONFIDENCE_JSONPATH;
505
+ Capabilities.SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100;
506
+ Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS;
507
+ Capabilities.SIMPLEREST_NLP_LIST_JSONPATH;
508
+ Capabilities.SIMPLEREST_NLP_LIST_INTENT_JSONPATH;
509
+ Capabilities.SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH;
496
510
  Capabilities.SCRIPTING_TXT_EOL;
497
511
  Capabilities.SCRIPTING_XLSX_MODE;
498
512
  Capabilities.SCRIPTING_XLSX_EOL_WRITE;
@@ -8425,6 +8439,75 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8425
8439
  }
8426
8440
  });
8427
8441
  debug$4(`found response cards: ${util__default["default"].inspect(cards)}`);
8442
+ let nlp = {
8443
+ intent: {}
8444
+ };
8445
+ const _normalizeIntent = intent => {
8446
+ if ('name' in intent) {
8447
+ if (!intent.name) {
8448
+ intent.name = 'None';
8449
+ }
8450
+ const fallbackIntents = this.caps[Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS];
8451
+ if (fallbackIntents) {
8452
+ intent.incomprehension = this.caps[Capabilities.SIMPLEREST_NLP_FALLBACK_INTENTS].includes(intent.name) ? true : undefined;
8453
+ } else {
8454
+ intent.incomprehension = intent.name.toLowerCase() === 'none' ? true : undefined;
8455
+ }
8456
+ }
8457
+ if (!lodash__default["default"].isNil(intent.confidence)) {
8458
+ if (typeof intent.confidence === 'string') {
8459
+ intent.confidence = Number(intent.confidence);
8460
+ }
8461
+ if (lodash__default["default"].isNil(this.caps[Capabilities.SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100]) ? intent.confidence > 1 : this.caps[Capabilities.SIMPLEREST_NLP_CONFIDENCE_DIVIDEBY100]) {
8462
+ intent.confidence /= 100;
8463
+ }
8464
+ }
8465
+ return intent;
8466
+ };
8467
+ const jsonPathIntent = this.caps[Capabilities.SIMPLEREST_NLP_INTENT_JSONPATH];
8468
+ if (jsonPathIntent) {
8469
+ const name = jsonpath__default["default"].query(jsonPathRoot, jsonPathIntent);
8470
+ nlp.intent.name = name?.length ? name[0] : null;
8471
+ }
8472
+ const jsonPathConfidence = this.caps[Capabilities.SIMPLEREST_NLP_CONFIDENCE_JSONPATH];
8473
+ if (jsonPathConfidence) {
8474
+ const confidence = jsonpath__default["default"].query(jsonPathRoot, jsonPathConfidence);
8475
+ nlp.intent.confidence = confidence?.length ? confidence[0] : null;
8476
+ }
8477
+ _normalizeIntent(nlp.intent);
8478
+ const jsonPathList = this.caps[Capabilities.SIMPLEREST_NLP_LIST_JSONPATH];
8479
+ const jsonPathListIntent = this.caps[Capabilities.SIMPLEREST_NLP_LIST_INTENT_JSONPATH];
8480
+ const jsonPathListConfidence = this.caps[Capabilities.SIMPLEREST_NLP_LIST_CONFIDENCE_JSONPATH];
8481
+ if (jsonPathList) {
8482
+ const list = jsonpath__default["default"].query(jsonPathRoot, jsonPathList);
8483
+ if (list?.length) {
8484
+ const intentList = list[0].map(e => {
8485
+ const name = jsonpath__default["default"].query(e, jsonPathListIntent);
8486
+ const res = {
8487
+ name: name?.length ? name[0] : null
8488
+ };
8489
+ if (jsonPathListConfidence) {
8490
+ const confidence = jsonpath__default["default"].query(e, jsonPathListConfidence);
8491
+ res.confidence = confidence?.length ? confidence[0] : null;
8492
+ }
8493
+ _normalizeIntent(res);
8494
+ return res;
8495
+ });
8496
+ if (intentList.length > 0 && !nlp.intent.name) {
8497
+ nlp.intent.name = intentList[0].name;
8498
+ nlp.intent.confidence = intentList[0].confidence;
8499
+ }
8500
+ if (nlp.intent.name === intentList[0].name) {
8501
+ intentList.shift();
8502
+ }
8503
+ nlp.intent.intents = intentList;
8504
+ }
8505
+ }
8506
+ if (Object.keys(nlp.intent).length > 0) {
8507
+ debug$4(`found response nlp: ${util__default["default"].inspect(nlp)}`);
8508
+ } else {
8509
+ nlp = null;
8510
+ }
8428
8511
  let hasMessageText = false;
8429
8512
  const jsonPathsTexts = getAllCapValues(Capabilities.SIMPLEREST_RESPONSE_JSONPATH, this.caps);
8430
8513
  for (const jsonPath of jsonPathsTexts) {
@@ -8440,7 +8523,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8440
8523
  messageText,
8441
8524
  media,
8442
8525
  buttons,
8443
- cards
8526
+ nlp
8444
8527
  };
8445
8528
  await executeHook(this.caps, this.responseHook, Object.assign({
8446
8529
  botMsg,
@@ -8456,7 +8539,8 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8456
8539
  sourceData: body,
8457
8540
  media,
8458
8541
  buttons,
8459
- cards
8542
+ cards,
8543
+ nlp
8460
8544
  };
8461
8545
  const beforeHookKeys = Object.keys(botMsg);
8462
8546
  await executeHook(this.caps, this.responseHook, Object.assign({
@@ -8464,7 +8548,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8464
8548
  botMsgRoot: jsonPathRoot
8465
8549
  }, this.view));
8466
8550
  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 || !this.caps[Capabilities.SIMPLEREST_IGNORE_EMPTY]) {
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]) {
8468
8552
  result.push(botMsg);
8469
8553
  }
8470
8554
  }
@@ -8489,7 +8573,8 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8489
8573
  fetch(requestOptions.uri, requestOptions).then(async bodyRaw => {
8490
8574
  let body;
8491
8575
  try {
8492
- if (bodyRaw.headers.get('content-type').includes('application/json')) {
8576
+ const contentType = bodyRaw.headers.get('content-type');
8577
+ if (contentType && contentType.includes('application/json')) {
8493
8578
  try {
8494
8579
  body = await bodyRaw.json();
8495
8580
  } catch (err) {