botium-core 1.14.4 → 1.14.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "botium-core",
3
- "version": "1.14.4",
3
+ "version": "1.14.6",
4
4
  "description": "The Selenium for Chatbots",
5
5
  "main": "index.js",
6
6
  "module": "dist/botium-es.js",
@@ -18,7 +18,7 @@
18
18
  "link": "npm link botium-connector-dialogflow botium-connector-webdriverio botium-connector-directline3 botium-connector-watson botium-connector-alexa-smapi botium-connector-echo",
19
19
  "test": "cross-env NODE_PATH=\"./test/plugins/plugindir/fromfolder:./test/plugins/plugindir/fromfile:./test/security/resources\" mocha \"./test/**/*.spec.js\"",
20
20
  "coverage:report": "nyc report --reporter=lcov npm test",
21
- "update-dependencies": "npm-check-updates --reject globby,rollup -u --timeout 120000"
21
+ "update-dependencies": "npm-check-updates --reject chai,globby,rollup -u --timeout 120000"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "homepage": "https://www.botium.ai",
33
33
  "dependencies": {
34
- "@babel/runtime": "^7.23.5",
34
+ "@babel/runtime": "^7.23.9",
35
35
  "async": "^3.2.5",
36
36
  "body-parser": "^1.20.2",
37
37
  "boolean": "^3.2.0",
@@ -48,8 +48,8 @@
48
48
  "markdown-it": "^14.0.0",
49
49
  "mime-types": "^2.1.35",
50
50
  "mkdirp": "^3.0.1",
51
- "moment": "^2.29.4",
52
- "moment-timezone": "^0.5.43",
51
+ "moment": "^2.30.1",
52
+ "moment-timezone": "^0.5.45",
53
53
  "mustache": "^4.2.0",
54
54
  "promise-retry": "^2.0.1",
55
55
  "promise.allsettled": "^1.0.7",
@@ -58,8 +58,8 @@
58
58
  "rimraf": "^5.0.5",
59
59
  "sanitize-filename": "^1.6.3",
60
60
  "slugify": "^1.6.6",
61
- "socket.io": "^4.7.2",
62
- "socket.io-client": "^4.7.2",
61
+ "socket.io": "^4.7.4",
62
+ "socket.io-client": "^4.7.4",
63
63
  "socketio-auth": "^0.1.1",
64
64
  "swagger-jsdoc": "^6.2.8",
65
65
  "swagger-ui-express": "^5.0.0",
@@ -71,23 +71,23 @@
71
71
  "yaml": "^2.3.4"
72
72
  },
73
73
  "devDependencies": {
74
- "@babel/core": "^7.23.5",
75
- "@babel/node": "^7.22.19",
76
- "@babel/plugin-transform-runtime": "^7.23.4",
77
- "@babel/preset-env": "^7.23.5",
78
- "chai": "^4.3.10",
74
+ "@babel/core": "^7.23.9",
75
+ "@babel/node": "^7.23.9",
76
+ "@babel/plugin-transform-runtime": "^7.23.9",
77
+ "@babel/preset-env": "^7.23.9",
78
+ "chai": "4.3.10",
79
79
  "chai-as-promised": "^7.1.1",
80
80
  "cross-env": "^7.0.3",
81
- "eslint": "^8.55.0",
81
+ "eslint": "^8.56.0",
82
82
  "eslint-config-standard": "^17.1.0",
83
- "eslint-plugin-import": "^2.29.0",
83
+ "eslint-plugin-import": "^2.29.1",
84
84
  "eslint-plugin-mocha": "^10.2.0",
85
- "eslint-plugin-n": "^16.4.0",
85
+ "eslint-plugin-n": "^16.6.2",
86
86
  "eslint-plugin-promise": "^6.1.1",
87
87
  "eslint-plugin-standard": "^4.1.0",
88
- "mocha": "^10.2.0",
89
- "nock": "^13.4.0",
90
- "npm-check-updates": "^16.14.11",
88
+ "mocha": "^10.3.0",
89
+ "nock": "^13.5.1",
90
+ "npm-check-updates": "^16.14.15",
91
91
  "nyc": "^15.1.0",
92
92
  "rollup": "2.79.1",
93
93
  "rollup-plugin-babel": "^4.4.0",
package/src/Defaults.js CHANGED
@@ -34,7 +34,6 @@ module.exports = {
34
34
  [Capabilities.SIMPLEREST_INBOUND_UPDATE_CONTEXT]: true,
35
35
  [Capabilities.SIMPLEREST_CONTEXT_MERGE_OR_REPLACE]: 'MERGE',
36
36
  [Capabilities.SIMPLEREST_COOKIE_REPLICATION]: true,
37
- [Capabilities.SCRIPTING_TXT_EOL]: '\n',
38
37
  [Capabilities.SCRIPTING_XLSX_EOL_WRITE]: '\r\n',
39
38
  [Capabilities.SCRIPTING_XLSX_HASHEADERS]: true,
40
39
  [Capabilities.SCRIPTING_CSV_SKIP_HEADER]: true,
@@ -3,7 +3,6 @@ const MarkdownIt = require('markdown-it')
3
3
  const util = require('util')
4
4
  const md = new MarkdownIt()
5
5
 
6
- const Capabilities = require('../Capabilities')
7
6
  const CompilerBase = require('./CompilerBase')
8
7
  const Constants = require('./Constants')
9
8
  const { Convo } = require('./Convo')
@@ -13,13 +12,10 @@ const { linesToConvoStep, validSenders, validateSender } = require('./helper')
13
12
  module.exports = class CompilerMarkdown extends CompilerBase {
14
13
  constructor (context, caps = {}) {
15
14
  super(context, caps)
16
-
17
- this.eol = caps[Capabilities.SCRIPTING_TXT_EOL]
18
15
  }
19
16
 
20
17
  Validate () {
21
18
  super.Validate()
22
- this._AssertCapabilityExists(Capabilities.SCRIPTING_TXT_EOL)
23
19
  }
24
20
 
25
21
  Compile (scriptBuffer, scriptType = Constants.SCRIPTING_TYPE_CONVO) {
@@ -90,7 +86,7 @@ module.exports = class CompilerMarkdown extends CompilerBase {
90
86
  },
91
87
  linesToConvoStep(step.children.map(child => child.content +
92
88
  (child.children && child.children.length > 0 ? ' ' + child.children.map(child => child.content).join('|') : '')
93
- ), sender, this.context, this.eol)
89
+ ), sender, this.context)
94
90
  ))
95
91
  } else {
96
92
  debug(`Expected sender ${validSenders.map(s => `'${s}'`).join(' or ')} but found ${sender}`)
@@ -11,13 +11,10 @@ const { linesToConvoStep, validSenders, linesToScriptingMemories } = require('./
11
11
  module.exports = class CompilerObjectBase extends CompilerBase {
12
12
  constructor (context, caps = {}) {
13
13
  super(context, caps)
14
-
15
- this.eol = caps[Capabilities.SCRIPTING_TXT_EOL]
16
14
  }
17
15
 
18
16
  Validate () {
19
17
  super.Validate()
20
- this._AssertCapabilityExists(Capabilities.SCRIPTING_TXT_EOL)
21
18
  }
22
19
 
23
20
  GetHeaders (scriptBuffer) {
@@ -69,7 +66,7 @@ module.exports = class CompilerObjectBase extends CompilerBase {
69
66
  sender: convoStepSender,
70
67
  stepTag: 'Line ' + lineTag
71
68
  },
72
- linesToConvoStep(convoStepObject, convoStepSender, this.context, this.eol)
69
+ linesToConvoStep(convoStepObject, convoStepSender, this.context)
73
70
  ))
74
71
  }
75
72
 
@@ -1,27 +1,29 @@
1
+ const _ = require('lodash')
2
+
1
3
  const Capabilities = require('../Capabilities')
2
4
  const Constants = require('./Constants')
3
5
  const CompilerBase = require('./CompilerBase')
4
6
  const Utterance = require('./Utterance')
5
7
  const { ConvoHeader, Convo } = require('./Convo')
6
- const { linesToConvoStep, convoStepToLines, validateConvo, validSenders, linesToScriptingMemories } = require('./helper')
8
+ const { linesToConvoStep, convoStepToLines, validateConvo, validSenders, linesToScriptingMemories, trimExceptSpaceEnd } = require('./helper')
7
9
 
8
10
  module.exports = class CompilerTxt extends CompilerBase {
9
11
  constructor (context, caps = {}) {
10
12
  super(context, caps)
11
13
 
12
- this.eol = caps[Capabilities.SCRIPTING_TXT_EOL]
14
+ this.eolRead = caps[Capabilities.SCRIPTING_TXT_EOL] || /\r\n|\r|\n/
15
+ this.eolWrite = (caps[Capabilities.SCRIPTING_TXT_EOL] && !_.isRegExp(caps[Capabilities.SCRIPTING_TXT_EOL])) ? caps[Capabilities.SCRIPTING_TXT_EOL] : '\n'
13
16
  }
14
17
 
15
18
  Validate () {
16
19
  super.Validate()
17
- this._AssertCapabilityExists(Capabilities.SCRIPTING_TXT_EOL)
18
20
  }
19
21
 
20
22
  GetHeaders (scriptBuffer) {
21
23
  let scriptData = scriptBuffer
22
24
  if (Buffer.isBuffer(scriptBuffer)) scriptData = scriptData.toString()
23
25
 
24
- const lines = scriptData.split(this.eol)
26
+ const lines = scriptData.split(this.eolRead)
25
27
 
26
28
  const header = { }
27
29
 
@@ -35,7 +37,7 @@ module.exports = class CompilerTxt extends CompilerBase {
35
37
  let scriptData = scriptBuffer
36
38
  if (Buffer.isBuffer(scriptBuffer)) scriptData = scriptData.toString()
37
39
 
38
- const lines = scriptData.split(this.eol)
40
+ const lines = scriptData.split(this.eolRead)
39
41
 
40
42
  if (scriptType === Constants.SCRIPTING_TYPE_CONVO) {
41
43
  return this._compileConvo(lines, false)
@@ -64,7 +66,7 @@ module.exports = class CompilerTxt extends CompilerBase {
64
66
 
65
67
  const parseMsg = (lines) => {
66
68
  lines = lines || []
67
- return linesToConvoStep(lines, convoStepSender, this.context, this.eol)
69
+ return linesToConvoStep(lines, convoStepSender, this.context)
68
70
  }
69
71
 
70
72
  const pushPrev = () => {
@@ -79,7 +81,7 @@ module.exports = class CompilerTxt extends CompilerBase {
79
81
  } else if (!convoStepSender && currentLines) {
80
82
  convo.header.name = currentLines[0]
81
83
  if (currentLines.length > 1) {
82
- convo.header.description = currentLines.slice(1).join(this.eol)
84
+ convo.header.description = currentLines.slice(1).join(this.eolWrite)
83
85
  }
84
86
  }
85
87
  }
@@ -120,7 +122,7 @@ module.exports = class CompilerTxt extends CompilerBase {
120
122
 
121
123
  _compileUtterances (lines) {
122
124
  if (lines && lines.length > 0) {
123
- const result = [new Utterance({ name: lines[0], utterances: lines.length > 1 ? lines.slice(1) : [] })]
125
+ const result = [new Utterance({ name: lines[0].trim(), utterances: lines.length > 1 ? lines.slice(1).map(line => trimExceptSpaceEnd(line)) : [] })]
124
126
  this.context.AddUtterances(result)
125
127
  return result
126
128
  }
@@ -151,23 +153,23 @@ module.exports = class CompilerTxt extends CompilerBase {
151
153
  let script = ''
152
154
 
153
155
  if (convo.header.name) {
154
- script += convo.header.name + this.eol
156
+ script += convo.header.name + this.eolWrite
155
157
  }
156
158
  if (convo.header.description) {
157
- script += convo.header.description + this.eol
159
+ script += convo.header.description + this.eolWrite
158
160
  }
159
161
 
160
162
  convo.conversation.forEach((step) => {
161
- script += this.eol
163
+ script += this.eolWrite
162
164
 
163
165
  script += '#' + step.sender
164
166
  if (step.channel && step.channel !== 'default') {
165
167
  script += ' ' + step.channel
166
168
  }
167
- script += this.eol
169
+ script += this.eolWrite
168
170
 
169
171
  const stepLines = convoStepToLines(step)
170
- if (stepLines && stepLines.length > 0) script += stepLines.join(this.eol) + this.eol
172
+ if (stepLines && stepLines.length > 0) script += stepLines.join(this.eolWrite) + this.eolWrite
171
173
  })
172
174
  return script
173
175
  }
@@ -1307,17 +1307,18 @@ module.exports = class ScriptingProvider {
1307
1307
  }
1308
1308
  if (utterances) {
1309
1309
  _.forEach(utterances, (utt) => {
1310
- const eu = this.utterances[utt.name]
1310
+ const uttName = utt.name?.trim()
1311
+ const eu = this.utterances[uttName]
1311
1312
  if (eu) {
1312
1313
  eu.utterances = _.uniq(_.concat(eu.utterances, utt.utterances))
1313
1314
  } else {
1314
- this.utterances[utt.name] = utt
1315
+ this.utterances[uttName] = utt
1315
1316
  }
1316
1317
 
1317
- const { ambiguous, expected } = findAmbiguous(this.utterances[utt.name].utterances)
1318
+ const { ambiguous, expected } = findAmbiguous(this.utterances[uttName].utterances)
1318
1319
 
1319
1320
  if (ambiguous && ambiguous.length > 0) {
1320
- debug(`Ambigous utterance "${utt.name}", expecting exact ${expected.length ? ('"' + expected.join(', ') + '"') : '<none>'} scripting memory variables in following user examples: ${ambiguous.map(d => `"${d}"`).join(', ')}`)
1321
+ debug(`Ambigous utterance "${uttName}", expecting exact ${expected.length ? ('"' + expected.join(', ') + '"') : '<none>'} scripting memory variables in following user examples: ${ambiguous.map(d => `"${d}"`).join(', ')}`)
1321
1322
  }
1322
1323
  })
1323
1324
  }
@@ -87,7 +87,7 @@ const _parseArgs = (str) => {
87
87
  return (str && str.length > 0 && str.replace(/\\\|/g, '###ESCAPESPLIT###').split('|').map(s => s.replace(/###ESCAPESPLIT###/g, '|').trim())) || []
88
88
  }
89
89
 
90
- const linesToConvoStep = (lines, sender, context, eol, singleLineMode = false) => {
90
+ const linesToConvoStep = (lines, sender, context, eol = '\n', singleLineMode = false) => {
91
91
  if (!validateSender(sender)) throw new Error(`Failed to parse conversation. Section "${sender}" unknown.`)
92
92
 
93
93
  const convoStep = { asserters: [], logicHooks: [], userInputs: [], not: false, optional: false, sender }
@@ -248,7 +248,7 @@ const linesToConvoStep = (lines, sender, context, eol, singleLineMode = false) =
248
248
  if (eol === null) {
249
249
  throw new Error('eol cant be null')
250
250
  }
251
- convoStep.messageText = textLines.join(eol).replace(WHITE_SPACES_EXCEPT_SPACE_CHAR_AT_THE_END, '')
251
+ convoStep.messageText = trimExceptSpaceEnd(textLines.join(eol))
252
252
  }
253
253
  }
254
254
  } else {
@@ -271,6 +271,10 @@ const linesToConvoStep = (lines, sender, context, eol, singleLineMode = false) =
271
271
  return convoStep
272
272
  }
273
273
 
274
+ const trimExceptSpaceEnd = (string) => {
275
+ return string?.replace(WHITE_SPACES_EXCEPT_SPACE_CHAR_AT_THE_END, '')
276
+ }
277
+
274
278
  const convoStepToObject = (step) => {
275
279
  const result = []
276
280
  if (step.sender === 'me') {
@@ -608,5 +612,6 @@ module.exports = {
608
612
  validateConvo,
609
613
  linesToScriptingMemories,
610
614
  calculateWer,
611
- toPercent
615
+ toPercent,
616
+ trimExceptSpaceEnd
612
617
  }
@@ -321,5 +321,18 @@ describe('compiler.compilertxt', function () {
321
321
  assert.equal(convo.conversation[0].asserters.length, 1)
322
322
  assert.deepEqual(convo.conversation[0].asserters[0], { name: 'BUTTONS', args: ['Test|1', 'Test|2'], not: false, optional: false })
323
323
  })
324
+ it('should read file with mixed new line characters', async function () {
325
+ const scriptBuffer = fs.readFileSync(path.resolve(__dirname, CONVOS_DIR, 'convos_mixed_new_line_characters.convo.txt'))
326
+ const context = buildContext()
327
+ const caps = {
328
+ }
329
+ const compiler = new Compiler(context, Object.assign({}, DefaultCapabilities, caps))
330
+ compiler.Compile(scriptBuffer, 'SCRIPTING_TYPE_CONVO')
331
+ const convo = context.convos[0]
332
+ assert.equal(convo.header.name, 'mixed new line characters (do not change in text editor!)')
333
+ assert.equal(convo.conversation[0].messageText, 'n')
334
+ assert.equal(convo.conversation[1].messageText, 'rn')
335
+ assert.equal(convo.conversation[2].messageText, 'r')
336
+ })
324
337
  })
325
338
  })
@@ -0,0 +1,10 @@
1
+ mixed new line characters (do not change in text editor!)
2
+
3
+ #me
4
+ n
5
+
6
+ #bot
7
+ rn
8
+
9
+ #bot
10
+ r