botium-core 1.13.2 → 1.13.3
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/.eslintrc.js +6 -3
- package/dist/botium-cjs.js +214 -61
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +213 -61
- package/dist/botium-es.js.map +1 -1
- package/package.json +3 -1
- package/src/Capabilities.js +2 -1
- package/src/containers/plugins/SimpleRestContainer.js +20 -16
- package/src/grid/inbound/proxy.js +2 -1
- package/src/scripting/Convo.js +16 -10
- package/src/scripting/MatchFunctions.js +10 -0
- package/src/scripting/ScriptingProvider.js +106 -37
- package/src/scripting/logichook/LogicHookConsts.js +1 -1
- package/src/scripting/logichook/asserter/WerAsserter.js +59 -0
- package/src/scripting/logichook/logichooks/UpdateCustomLogicHook.js +3 -2
- package/test/compiler/compilercsv.spec.js +104 -3
- package/test/compiler/compilerjson.spec.js +0 -2
- package/test/compiler/compilerxlsx.spec.js +1 -1
- package/test/compiler/convos/csv/utterances_liveperson2.csv +12 -0
- package/test/connectors/simplerest.spec.js +1012 -969
- package/test/convo/fillAndApplyScriptingMemory.spec.js +804 -785
- package/test/convo/partialconvo.spec.js +345 -339
- package/test/driver/capabilities.spec.js +156 -151
- package/test/logichooks/hookfromsrc.spec.js +79 -73
- package/test/plugins/plugins.spec.js +44 -42
- package/test/scripting/asserters/buttonsAsserter.spec.js +257 -240
- package/test/scripting/asserters/cardsAsserter.spec.js +214 -212
- package/test/scripting/asserters/convos/wer_threshold_nok.yml +7 -0
- package/test/scripting/asserters/convos/wer_threshold_ok.yml +7 -0
- package/test/scripting/asserters/intentConfidenceAsserter.spec.js +34 -35
- package/test/scripting/asserters/jsonpathAsserter.spec.js +307 -308
- package/test/scripting/asserters/mediaAsserter.spec.js +236 -234
- package/test/scripting/asserters/werAsserter.spec.js +51 -0
- package/test/scripting/logichooks/setClearScriptingMemory.spec.js +202 -192
- package/test/scripting/matching/matchingmode.spec.js +306 -258
- package/test/scripting/scriptingProvider.spec.js +666 -633
- package/test/scripting/scriptingmemory/fillScriptingMemoryFromFile.spec.js +299 -281
- package/test/scripting/scriptingmemory/useScriptingMemoryForAssertion.spec.js +94 -80
- package/test/scripting/userinputs/defaultUserInputs.spec.js +233 -127
- package/test/scripting/userinputs/mediaInputConvos.spec.js +409 -403
- package/test/scripting/utteranceexpansion/associateByIndex.spec.js +259 -0
- package/test/scripting/utteranceexpansion/convos/associate_utterances_by_index.json +33 -0
- package/test/scripting/utteranceexpansion/convos/media.convo.txt +19 -0
- package/test/scripting/utteranceexpansion/files/step0voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step1voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice4.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice5.wav +0 -0
- package/test/security/allowUnsafe.spec.js +274 -268
- package/test/utils.spec.js +40 -38
|
@@ -7,204 +7,214 @@ const echoConnector = ({ queueBotSays }) => {
|
|
|
7
7
|
return {
|
|
8
8
|
UserSays (msg) {
|
|
9
9
|
const response = msg.messageText && msg.messageText.replace('INPUT1', 'OUTPUT1').replace('INPUT2', 'OUTPUT2')
|
|
10
|
-
const botMsg = {
|
|
10
|
+
const botMsg = {
|
|
11
|
+
sender: 'bot',
|
|
12
|
+
sourceData: msg.sourceData,
|
|
13
|
+
messageText: response,
|
|
14
|
+
cards: [{
|
|
15
|
+
text: 'card text',
|
|
16
|
+
content: 'card content'
|
|
17
|
+
}]
|
|
18
|
+
}
|
|
11
19
|
queueBotSays(botMsg)
|
|
12
20
|
}
|
|
13
21
|
}
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
describe('
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
24
|
+
describe('scripting.logichooks.global.setClearScriptingMemory', function () {
|
|
25
|
+
describe('SetClearScriptingMemory', function () {
|
|
26
|
+
beforeEach(async function () {
|
|
27
|
+
const myCaps = {
|
|
28
|
+
[Capabilities.PROJECTNAME]: 'scripting.logichooks',
|
|
29
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
30
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true
|
|
31
|
+
}
|
|
32
|
+
const driver = new BotDriver(myCaps)
|
|
33
|
+
this.compiler = driver.BuildCompiler()
|
|
34
|
+
this.container = await driver.Build()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
afterEach(async function () {
|
|
38
|
+
this.container && await this.container.Clean()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should be created by begin', async function () {
|
|
42
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_created_by_begin.convo.txt')
|
|
43
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
44
|
+
|
|
45
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
46
|
+
assert.isObject(transcript.scriptingMemory)
|
|
47
|
+
assert.isDefined(transcript.scriptingMemory.$created_by_begin)
|
|
48
|
+
assert.equal(transcript.scriptingMemory.$created_by_begin, 'created_by_begin_from_begin')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('should be created two by begin', async function () {
|
|
52
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_created_two_by_begin.convo.txt')
|
|
53
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
54
|
+
|
|
55
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
56
|
+
assert.isObject(transcript.scriptingMemory)
|
|
57
|
+
assert.isDefined(transcript.scriptingMemory.$created_by_begin_one)
|
|
58
|
+
assert.equal(transcript.scriptingMemory.$created_by_begin_one, 'created_by_begin_one_from_begin')
|
|
59
|
+
assert.isDefined(transcript.scriptingMemory.$created_by_begin_two)
|
|
60
|
+
assert.equal(transcript.scriptingMemory.$created_by_begin_two, 'created_by_begin_two_from_begin')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should be created by logic hook', async function () {
|
|
64
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_created_by_logic_hook.convo.txt')
|
|
65
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
66
|
+
|
|
67
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
68
|
+
assert.isObject(transcript.scriptingMemory)
|
|
69
|
+
assert.isDefined(transcript.scriptingMemory.$created_by_logic_hook)
|
|
70
|
+
assert.equal(transcript.scriptingMemory.$created_by_logic_hook, 'created_by_logic_hook_from_logic_hook')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('should be cleared by logic hook', async function () {
|
|
74
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_cleared_by_logic_hook.convo.txt')
|
|
75
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
76
|
+
|
|
77
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
78
|
+
assert.isObject(transcript.scriptingMemory)
|
|
79
|
+
assert.notExists(transcript.scriptingMemory.cleared_by_logic_hook)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('should be overwritten by convo', async function () {
|
|
83
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_overwritten_by_convo.convo.txt')
|
|
84
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
85
|
+
|
|
86
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
87
|
+
assert.isObject(transcript.scriptingMemory)
|
|
88
|
+
assert.isDefined(transcript.scriptingMemory.$overwritten_by_convo)
|
|
89
|
+
assert.equal(transcript.scriptingMemory.$overwritten_by_convo, 'overwritten_by_convo_from_begin')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('should be overwritten by logic hook', async function () {
|
|
93
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_overwritten_by_logic_hook.convo.txt')
|
|
94
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
95
|
+
|
|
96
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
97
|
+
assert.isObject(transcript.scriptingMemory)
|
|
98
|
+
assert.isDefined(transcript.scriptingMemory.$overwritten_by_logic_hook)
|
|
99
|
+
assert.equal(transcript.scriptingMemory.$overwritten_by_logic_hook, 'overwritten_by_logic_hook_from_logic_hook')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('reserved word, just a log on console', async function () {
|
|
103
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_reserved_word.convo.txt')
|
|
104
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
105
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
106
|
+
assert.isObject(transcript.scriptingMemory)
|
|
107
|
+
assert.isDefined(transcript.scriptingMemory.$year)
|
|
108
|
+
assert.equal(transcript.scriptingMemory.$year, '2012')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('numbers, parse currencies', async function () {
|
|
112
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_numbers.convo.txt')
|
|
113
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
114
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
115
|
+
assert.isObject(transcript.scriptingMemory)
|
|
116
|
+
// assert.isDefined(transcript.scriptingMemory['$year'])
|
|
117
|
+
// assert.equal(transcript.scriptingMemory['$year'], '2012')
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('should use scripting memory for assertions', async function () {
|
|
121
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_progress.convo.txt')
|
|
122
|
+
try {
|
|
123
|
+
await this.compiler.convos[0].Run(this.container)
|
|
124
|
+
assert.fail('should have failed')
|
|
125
|
+
} catch (err) {
|
|
126
|
+
assert.isTrue(err.message.indexOf('Bot response (on Line 6: #me - sending input: $input) "sending input: OUTPUT1" expected to match "sending input: INPUT1"') >= 0)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
it('should overwrite scripting memory and use for assertions', async function () {
|
|
130
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_overwrite_and_check.convo.txt')
|
|
131
|
+
try {
|
|
132
|
+
await this.compiler.convos[0].Run(this.container)
|
|
133
|
+
assert.fail('should have failed')
|
|
134
|
+
} catch (err) {
|
|
135
|
+
assert.isTrue(err.message.indexOf('Bot response (on Line 9: #me - this is a variable: VARVALUE2) "this is a variable: VARVALUE2" expected to match "this is a variable: VARVALUE1"') >= 0)
|
|
136
|
+
assert.isUndefined(err.transcript.steps[0].scriptingMemory.$myvar)
|
|
137
|
+
assert.equal(err.transcript.steps[1].scriptingMemory.$myvar, 'VARVALUE1')
|
|
138
|
+
assert.equal(err.transcript.steps[2].scriptingMemory.$myvar, 'VARVALUE1')
|
|
139
|
+
assert.equal(err.transcript.steps[3].scriptingMemory.$myvar, 'VARVALUE1')
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
it('should be assigned from jsonpath', async function () {
|
|
143
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_from_jsonpath.convo.txt')
|
|
144
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
145
|
+
|
|
146
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
147
|
+
assert.isObject(transcript.scriptingMemory)
|
|
148
|
+
assert.isDefined(transcript.scriptingMemory.$cardcontent)
|
|
149
|
+
assert.equal(transcript.scriptingMemory.$cardcontent, 'card content')
|
|
150
|
+
})
|
|
151
|
+
it('should fail on invalid jsonpath', async function () {
|
|
152
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_from_invalidjsonpath.convo.txt')
|
|
153
|
+
try {
|
|
154
|
+
await this.compiler.convos[0].Run(this.container)
|
|
155
|
+
assert.fail('should have failed')
|
|
156
|
+
} catch (err) {
|
|
157
|
+
assert.isTrue(err.message.indexOf('no result from JSON-Path query') >= 0)
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe('global', function () {
|
|
163
|
+
beforeEach(async function () {
|
|
164
|
+
const myCaps = {
|
|
165
|
+
[Capabilities.PROJECTNAME]: 'scripting.logichooks',
|
|
166
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
167
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
168
|
+
[Capabilities.LOGIC_HOOKS]: [
|
|
169
|
+
{
|
|
170
|
+
src: 'SetScriptingMemoryLogicHook',
|
|
171
|
+
ref: 'created_by_global',
|
|
172
|
+
global: true,
|
|
173
|
+
args: {
|
|
174
|
+
name: 'created_by_global',
|
|
175
|
+
value: 'created_by_global_from_global'
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
src: 'SetScriptingMemoryLogicHook',
|
|
180
|
+
ref: 'created_by_begin',
|
|
181
|
+
global: true,
|
|
182
|
+
args: {
|
|
183
|
+
name: 'created_by_begin',
|
|
184
|
+
value: 'created_by_begin_from_global'
|
|
185
|
+
}
|
|
176
186
|
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
]
|
|
180
|
-
}
|
|
181
|
-
const driver = new BotDriver(myCaps)
|
|
182
|
-
this.compiler = driver.BuildCompiler()
|
|
183
|
-
this.container = await driver.Build()
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
afterEach(async function () {
|
|
187
|
-
this.container && await this.container.Clean()
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
it('should be created by global', async function () {
|
|
191
|
-
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'no_scripting_memory.convo.txt')
|
|
192
|
-
assert.equal(this.compiler.convos.length, 1)
|
|
193
|
-
|
|
194
|
-
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
195
|
-
assert.isObject(transcript.scriptingMemory)
|
|
196
|
-
assert.isDefined(transcript.scriptingMemory.$created_by_global)
|
|
197
|
-
assert.equal(transcript.scriptingMemory.$created_by_global, 'created_by_global_from_global')
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
// It must be just an accident that the global is overwritten by begin. feel free to change this test
|
|
201
|
-
it('should be overwritten by global', async function () {
|
|
202
|
-
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_created_by_begin.convo.txt')
|
|
203
|
-
assert.equal(this.compiler.convos.length, 1)
|
|
204
187
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
const driver = new BotDriver(myCaps)
|
|
191
|
+
this.compiler = driver.BuildCompiler()
|
|
192
|
+
this.container = await driver.Build()
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
afterEach(async function () {
|
|
196
|
+
this.container && await this.container.Clean()
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
it('should be created by global', async function () {
|
|
200
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'no_scripting_memory.convo.txt')
|
|
201
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
202
|
+
|
|
203
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
204
|
+
assert.isObject(transcript.scriptingMemory)
|
|
205
|
+
assert.isDefined(transcript.scriptingMemory.$created_by_global)
|
|
206
|
+
assert.equal(transcript.scriptingMemory.$created_by_global, 'created_by_global_from_global')
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
// It must be just an accident that the global is overwritten by begin. feel free to change this test
|
|
210
|
+
it('should be overwritten by global', async function () {
|
|
211
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'scripting_memory_created_by_begin.convo.txt')
|
|
212
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
213
|
+
|
|
214
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
215
|
+
assert.isObject(transcript.scriptingMemory)
|
|
216
|
+
assert.isDefined(transcript.scriptingMemory.$created_by_begin)
|
|
217
|
+
assert.equal(transcript.scriptingMemory.$created_by_begin, 'created_by_begin_from_global')
|
|
218
|
+
})
|
|
209
219
|
})
|
|
210
220
|
})
|