botium-core 1.14.5 → 1.14.7
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 +42 -45
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +42 -45
- package/dist/botium-es.js.map +1 -1
- package/package.json +18 -18
- package/src/Defaults.js +0 -1
- package/src/containers/PluginConnectorContainer.js +5 -5
- package/src/helpers/RetryHelper.js +3 -1
- package/src/scripting/CompilerMarkdown.js +1 -5
- package/src/scripting/CompilerObjectBase.js +1 -4
- package/src/scripting/CompilerTxt.js +13 -11
- package/src/scripting/ScriptingProvider.js +2 -2
- package/src/scripting/helper.js +1 -1
- package/test/compiler/compilertxt.spec.js +13 -0
- package/test/compiler/convos/txt/convos_mixed_new_line_characters.convo.txt +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "botium-core",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.7",
|
|
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.
|
|
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.
|
|
52
|
-
"moment-timezone": "^0.5.
|
|
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.
|
|
62
|
-
"socket.io-client": "^4.7.
|
|
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.
|
|
75
|
-
"@babel/node": "^7.
|
|
76
|
-
"@babel/plugin-transform-runtime": "^7.23.
|
|
77
|
-
"@babel/preset-env": "^7.23.
|
|
78
|
-
"chai": "
|
|
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.
|
|
81
|
+
"eslint": "^8.56.0",
|
|
82
82
|
"eslint-config-standard": "^17.1.0",
|
|
83
|
-
"eslint-plugin-import": "^2.29.
|
|
83
|
+
"eslint-plugin-import": "^2.29.1",
|
|
84
84
|
"eslint-plugin-mocha": "^10.2.0",
|
|
85
|
-
"eslint-plugin-n": "^16.
|
|
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.
|
|
89
|
-
"nock": "^13.
|
|
90
|
-
"npm-check-updates": "^16.14.
|
|
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,
|
|
@@ -44,7 +44,7 @@ module.exports = class PluginConnectorContainer extends BaseContainer {
|
|
|
44
44
|
return super.Build().then(() => promiseRetry((retry, number) => {
|
|
45
45
|
return (this.pluginInstance.Build ? (this.pluginInstance.Build() || Promise.resolve()) : Promise.resolve())
|
|
46
46
|
.catch((err) => {
|
|
47
|
-
if (this.retryHelperBuild.shouldRetry(err)) {
|
|
47
|
+
if (this.retryHelperBuild.shouldRetry(err, number)) {
|
|
48
48
|
debug(`Build trial #${number} failed, retry activated`)
|
|
49
49
|
retry(err)
|
|
50
50
|
} else {
|
|
@@ -65,7 +65,7 @@ module.exports = class PluginConnectorContainer extends BaseContainer {
|
|
|
65
65
|
return super.Start().then(() => promiseRetry((retry, number) => {
|
|
66
66
|
return (this.pluginInstance.Start ? (this.pluginInstance.Start() || Promise.resolve()) : Promise.resolve())
|
|
67
67
|
.catch((err) => {
|
|
68
|
-
if (this.retryHelperStart.shouldRetry(err)) {
|
|
68
|
+
if (this.retryHelperStart.shouldRetry(err, number)) {
|
|
69
69
|
debug(`Start trial #${number} failed, retry activated`)
|
|
70
70
|
retry(err)
|
|
71
71
|
} else {
|
|
@@ -91,7 +91,7 @@ module.exports = class PluginConnectorContainer extends BaseContainer {
|
|
|
91
91
|
return promiseRetry((retry, number) => {
|
|
92
92
|
return (this.pluginInstance.UserSays(mockMsg) || Promise.resolve())
|
|
93
93
|
.catch((err) => {
|
|
94
|
-
if (this.retryHelperUserSays.shouldRetry(err)) {
|
|
94
|
+
if (this.retryHelperUserSays.shouldRetry(err, number)) {
|
|
95
95
|
debug(`UserSays trial #${number} failed, retry activated`)
|
|
96
96
|
retry(err)
|
|
97
97
|
} else {
|
|
@@ -115,7 +115,7 @@ module.exports = class PluginConnectorContainer extends BaseContainer {
|
|
|
115
115
|
return super.Stop().then(() => promiseRetry((retry, number) => {
|
|
116
116
|
return (this.pluginInstance.Stop ? (this.pluginInstance.Stop() || Promise.resolve()) : Promise.resolve())
|
|
117
117
|
.catch((err) => {
|
|
118
|
-
if (this.retryHelperStop.shouldRetry(err)) {
|
|
118
|
+
if (this.retryHelperStop.shouldRetry(err, number)) {
|
|
119
119
|
debug(`Stop trial #${number} failed, retry activated`)
|
|
120
120
|
retry(err)
|
|
121
121
|
} else {
|
|
@@ -142,7 +142,7 @@ module.exports = class PluginConnectorContainer extends BaseContainer {
|
|
|
142
142
|
return promiseRetry((retry, number) => {
|
|
143
143
|
return (this.pluginInstance.Clean ? (this.pluginInstance.Clean() || Promise.resolve()) : Promise.resolve())
|
|
144
144
|
.catch((err) => {
|
|
145
|
-
if (this.retryHelperClean.shouldRetry(err)) {
|
|
145
|
+
if (this.retryHelperClean.shouldRetry(err, number)) {
|
|
146
146
|
debug(`Clean trial #${number} failed, retry activated`)
|
|
147
147
|
retry(err)
|
|
148
148
|
} else {
|
|
@@ -30,8 +30,10 @@ module.exports = class RetryHelper {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
shouldRetry (err) {
|
|
33
|
+
shouldRetry (err, currentRetryCount) {
|
|
34
34
|
if (!err) return false
|
|
35
|
+
if (!this.retrySettings.retries) return false
|
|
36
|
+
if (this.retrySettings.retries < currentRetryCount) return false
|
|
35
37
|
if (this.retryErrorPatterns.length === 0) return true
|
|
36
38
|
const errString = util.inspect(err)
|
|
37
39
|
for (const re of this.retryErrorPatterns) {
|
|
@@ -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
|
|
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
|
|
69
|
+
linesToConvoStep(convoStepObject, convoStepSender, this.context)
|
|
73
70
|
))
|
|
74
71
|
}
|
|
75
72
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const _ = require('lodash')
|
|
2
|
+
|
|
1
3
|
const Capabilities = require('../Capabilities')
|
|
2
4
|
const Constants = require('./Constants')
|
|
3
5
|
const CompilerBase = require('./CompilerBase')
|
|
@@ -9,19 +11,19 @@ module.exports = class CompilerTxt extends CompilerBase {
|
|
|
9
11
|
constructor (context, caps = {}) {
|
|
10
12
|
super(context, caps)
|
|
11
13
|
|
|
12
|
-
this.
|
|
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.
|
|
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.
|
|
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
|
|
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.
|
|
84
|
+
convo.header.description = currentLines.slice(1).join(this.eolWrite)
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
}
|
|
@@ -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.
|
|
156
|
+
script += convo.header.name + this.eolWrite
|
|
155
157
|
}
|
|
156
158
|
if (convo.header.description) {
|
|
157
|
-
script += convo.header.description + this.
|
|
159
|
+
script += convo.header.description + this.eolWrite
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
convo.conversation.forEach((step) => {
|
|
161
|
-
script += this.
|
|
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.
|
|
169
|
+
script += this.eolWrite
|
|
168
170
|
|
|
169
171
|
const stepLines = convoStepToLines(step)
|
|
170
|
-
if (stepLines && stepLines.length > 0) script += stepLines.join(this.
|
|
172
|
+
if (stepLines && stepLines.length > 0) script += stepLines.join(this.eolWrite) + this.eolWrite
|
|
171
173
|
})
|
|
172
174
|
return script
|
|
173
175
|
}
|
|
@@ -36,7 +36,7 @@ const p = (retryHelper, fn) => {
|
|
|
36
36
|
if (retryHelper) {
|
|
37
37
|
return promiseRetry((retry, number) => {
|
|
38
38
|
return promise().catch(err => {
|
|
39
|
-
if (retryHelper.shouldRetry(err)) {
|
|
39
|
+
if (retryHelper.shouldRetry(err, number)) {
|
|
40
40
|
debug(`Asserter trial #${number} failed, retry activated`)
|
|
41
41
|
retry(err)
|
|
42
42
|
} else {
|
|
@@ -62,7 +62,7 @@ const pnot = (retryHelper, fn, errTemplate) => {
|
|
|
62
62
|
if (retryHelper) {
|
|
63
63
|
return promiseRetry((retry, number) => {
|
|
64
64
|
return promise().catch(() => {
|
|
65
|
-
if (retryHelper.shouldRetry(errTemplate)) {
|
|
65
|
+
if (retryHelper.shouldRetry(errTemplate, number)) {
|
|
66
66
|
debug(`Asserter trial #${number} failed, !retry activated`)
|
|
67
67
|
retry(errTemplate)
|
|
68
68
|
} else {
|
package/src/scripting/helper.js
CHANGED
|
@@ -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 }
|
|
@@ -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
|
})
|