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
|
@@ -8,442 +8,448 @@ const Capabilities = require('../../../').Capabilities
|
|
|
8
8
|
const echoConnector = ({ queueBotSays }) => {
|
|
9
9
|
return {
|
|
10
10
|
UserSays (msg) {
|
|
11
|
-
const botMsg = {
|
|
11
|
+
const botMsg = {
|
|
12
|
+
sender: 'bot',
|
|
13
|
+
sourceData: msg.sourceData,
|
|
14
|
+
messageText: msg.messageText
|
|
15
|
+
}
|
|
12
16
|
queueBotSays(botMsg)
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
describe('scripting.userinputs.mediaInputConvos
|
|
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
|
-
|
|
21
|
+
describe('scripting.userinputs.mediaInputConvos', function () {
|
|
22
|
+
describe('relative', function () {
|
|
23
|
+
beforeEach(async function () {
|
|
24
|
+
const myCaps = {
|
|
25
|
+
[Capabilities.PROJECTNAME]: 'scripting.userinputs.mediaInputConvos',
|
|
26
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
27
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true
|
|
28
|
+
}
|
|
29
|
+
const driver = new BotDriver(myCaps)
|
|
30
|
+
this.compiler = driver.BuildCompiler()
|
|
31
|
+
this.container = await driver.Build()
|
|
32
|
+
})
|
|
33
|
+
afterEach(async function () {
|
|
34
|
+
this.container && await this.container.Clean()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should fail on media with no arg', async function () {
|
|
38
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'mediaNoArg.convo.txt')
|
|
39
|
+
try {
|
|
40
|
+
await this.compiler.convos[0].Run(this.container)
|
|
41
|
+
assert.fail('it should have failed')
|
|
42
|
+
} catch (err) {
|
|
43
|
+
assert.isTrue(err.message.indexOf('Line 3: MediaInput requires at least 1 and at most 2 arguments') > 0)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('should add media in user message', async function () {
|
|
48
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'media.convo.txt')
|
|
49
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
50
|
+
assert.equal(this.compiler.convos[0].conversation.length, 1)
|
|
51
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs.length, 1)
|
|
52
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].name, 'MEDIA')
|
|
53
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].args.length, 1)
|
|
54
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].args[0], 'botium.png')
|
|
55
|
+
|
|
56
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
57
|
+
assert.equal(transcript.steps.length, 1)
|
|
58
|
+
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
59
|
+
assert.isTrue(transcript.steps[0].actual.media[0].downloadUri.endsWith('test/scripting/userinputs/convos/botium.png'))
|
|
60
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should fail when media is out of convo dir', async function () {
|
|
64
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'mediaOutOfConvoDir.convo.txt')
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
await this.compiler.convos[0].Run(this.container)
|
|
68
|
+
assert.fail('expected error')
|
|
69
|
+
} catch (err) {
|
|
70
|
+
assert.isTrue(err.message.startsWith('mediaoutofconvodir/Line 3: error sending to bot - The uri \'../botium.png\' is pointing out of the base directory'))
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('should add multi media in user message', async function () {
|
|
75
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'medias.convo.txt')
|
|
76
|
+
|
|
77
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
78
|
+
assert.equal(transcript.steps.length, 1)
|
|
79
|
+
assert.equal(transcript.steps[0].actual.media.length, 2)
|
|
80
|
+
assert.isTrue(transcript.steps[0].actual.media[0].downloadUri.endsWith('test/scripting/userinputs/convos/test1.jpg'))
|
|
81
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/jpeg')
|
|
82
|
+
assert.isTrue(transcript.steps[0].actual.media[1].downloadUri.endsWith('test/scripting/userinputs/convos/test2.jpg'))
|
|
83
|
+
assert.equal(transcript.steps[0].actual.media[1].mimeType, 'image/jpeg')
|
|
84
|
+
})
|
|
85
|
+
it('should expand media list in user message', async function () {
|
|
86
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'medialist.convo.txt')
|
|
87
|
+
this.compiler.ExpandConvos()
|
|
88
|
+
assert.equal(this.compiler.convos.length, 3)
|
|
89
|
+
assert.equal(this.compiler.convos[0].conversation.length, 1)
|
|
90
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs.length, 1)
|
|
91
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].args[0], 'test1.jpg')
|
|
92
|
+
assert.equal(this.compiler.convos[1].conversation[0].userInputs[0].args[0], 'test2.jpg')
|
|
93
|
+
assert.equal(this.compiler.convos[2].conversation[0].userInputs[0].args[0], 'test3.jpg')
|
|
94
|
+
})
|
|
95
|
+
it('should expand media wc from convoDir in user message', async function () {
|
|
96
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'mediawc.convo.txt')
|
|
97
|
+
this.compiler.ExpandConvos()
|
|
98
|
+
assert.equal(this.compiler.convos.length, 3)
|
|
99
|
+
assert.equal(this.compiler.convos[0].conversation.length, 1)
|
|
100
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs.length, 1)
|
|
101
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].args[0], 'files/botium0.png')
|
|
102
|
+
assert.equal(this.compiler.convos[1].conversation[0].userInputs[0].args[0], 'files/botium1.png')
|
|
103
|
+
assert.equal(this.compiler.convos[2].conversation[0].userInputs[0].args[0], 'files/botium2.png')
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('should use dataUri as media in user message', async function () {
|
|
107
|
+
const mediaData = fs.readFileSync(path.resolve(__dirname, 'convos', 'files', 'botium0.png'))
|
|
108
|
+
const mediaUri = `data:image/png;base64,${mediaData.toString('base64')}`
|
|
109
|
+
const script = `should use dataUri as media in user message
|
|
105
110
|
|
|
106
111
|
#me
|
|
107
112
|
MEDIA ${mediaUri}
|
|
108
113
|
`
|
|
109
114
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
this.compiler.Compile(script, 'SCRIPTING_FORMAT_TXT', 'SCRIPTING_TYPE_CONVO')
|
|
116
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
117
|
+
assert.equal(this.compiler.convos[0].conversation.length, 1)
|
|
118
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs.length, 1)
|
|
119
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].name, 'MEDIA')
|
|
120
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].args.length, 1)
|
|
121
|
+
assert.isTrue(this.compiler.convos[0].conversation[0].userInputs[0].args[0].startsWith('data:image/png'))
|
|
122
|
+
|
|
123
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
124
|
+
assert.equal(transcript.steps.length, 1)
|
|
125
|
+
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
126
|
+
assert.isTrue(transcript.steps[0].actual.media[0].downloadUri.startsWith('data:image/png'))
|
|
127
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
128
|
+
})
|
|
123
129
|
})
|
|
124
|
-
})
|
|
125
130
|
|
|
126
|
-
describe('
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
describe('baseUri', function () {
|
|
132
|
+
beforeEach(async function () {
|
|
133
|
+
const myCaps = {
|
|
134
|
+
[Capabilities.PROJECTNAME]: 'scripting.userinputs.mediaInputConvos',
|
|
135
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
136
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
137
|
+
[Capabilities.USER_INPUTS]: [
|
|
138
|
+
{
|
|
139
|
+
ref: 'MEDIA',
|
|
140
|
+
src: 'MediaInput',
|
|
141
|
+
args: {
|
|
142
|
+
baseUri: 'https://www.botium.at'
|
|
143
|
+
}
|
|
138
144
|
}
|
|
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
|
-
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
const driver = new BotDriver(myCaps)
|
|
148
|
+
this.compiler = driver.BuildCompiler()
|
|
149
|
+
this.container = await driver.Build()
|
|
150
|
+
})
|
|
151
|
+
afterEach(async function () {
|
|
152
|
+
this.container && await this.container.Clean()
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('should add media in user message', async function () {
|
|
156
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'media.convo.txt')
|
|
157
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
158
|
+
assert.equal(this.compiler.convos[0].conversation.length, 1)
|
|
159
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs.length, 1)
|
|
160
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].name, 'MEDIA')
|
|
161
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].args.length, 1)
|
|
162
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].args[0], 'botium.png')
|
|
163
|
+
|
|
164
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
165
|
+
assert.equal(transcript.steps.length, 1)
|
|
166
|
+
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
167
|
+
assert.equal(transcript.steps[0].actual.media[0].downloadUri, 'https://www.botium.at/botium.png')
|
|
168
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
it('should add multi media in user message', async function () {
|
|
172
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'medias.convo.txt')
|
|
173
|
+
|
|
174
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
175
|
+
assert.equal(transcript.steps.length, 1)
|
|
176
|
+
assert.equal(transcript.steps[0].actual.media.length, 2)
|
|
177
|
+
assert.equal(transcript.steps[0].actual.media[0].downloadUri, 'https://www.botium.at/test1.jpg')
|
|
178
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/jpeg')
|
|
179
|
+
assert.equal(transcript.steps[0].actual.media[1].downloadUri, 'https://www.botium.at/test2.jpg')
|
|
180
|
+
assert.equal(transcript.steps[0].actual.media[1].mimeType, 'image/jpeg')
|
|
181
|
+
})
|
|
164
182
|
})
|
|
165
183
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
[Capabilities.PROJECTNAME]: 'scripting.userinputs.mediaInputConvos',
|
|
183
|
-
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
184
|
-
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
185
|
-
[Capabilities.USER_INPUTS]: [
|
|
186
|
-
{
|
|
187
|
-
ref: 'MEDIA',
|
|
188
|
-
src: 'MediaInput',
|
|
189
|
-
args: {
|
|
190
|
-
baseUri: 'https://www.default.at',
|
|
191
|
-
baseUris: {
|
|
192
|
-
testset1: 'https://www.botium.at',
|
|
193
|
-
testset2: 'https://www.google.at'
|
|
184
|
+
describe('baseUris', function () {
|
|
185
|
+
beforeEach(async function () {
|
|
186
|
+
const myCaps = {
|
|
187
|
+
[Capabilities.PROJECTNAME]: 'scripting.userinputs.mediaInputConvos',
|
|
188
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
189
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
190
|
+
[Capabilities.USER_INPUTS]: [
|
|
191
|
+
{
|
|
192
|
+
ref: 'MEDIA',
|
|
193
|
+
src: 'MediaInput',
|
|
194
|
+
args: {
|
|
195
|
+
baseUri: 'https://www.default.at',
|
|
196
|
+
baseUris: {
|
|
197
|
+
testset1: 'https://www.botium.at',
|
|
198
|
+
testset2: 'https://www.google.at'
|
|
199
|
+
}
|
|
194
200
|
}
|
|
195
201
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
const driver = new BotDriver(myCaps)
|
|
205
|
+
this.compiler = driver.BuildCompiler()
|
|
206
|
+
this.container = await driver.Build()
|
|
207
|
+
})
|
|
208
|
+
afterEach(async function () {
|
|
209
|
+
this.container && await this.container.Clean()
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it('should add media from test set baseUri in user message', async function () {
|
|
213
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'media.convo.txt')
|
|
214
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
215
|
+
|
|
216
|
+
this.compiler.convos[0].sourceTag.testSetId = 'testset2'
|
|
217
|
+
|
|
218
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
219
|
+
assert.equal(transcript.steps.length, 1)
|
|
220
|
+
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
221
|
+
assert.equal(transcript.steps[0].actual.media[0].downloadUri, 'https://www.google.at/botium.png')
|
|
222
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
223
|
+
})
|
|
224
|
+
it('should add media with default baseUri in user message', async function () {
|
|
225
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'media.convo.txt')
|
|
226
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
227
|
+
|
|
228
|
+
this.compiler.convos[0].sourceTag.testSetId = 'testset3'
|
|
229
|
+
|
|
230
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
231
|
+
assert.equal(transcript.steps.length, 1)
|
|
232
|
+
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
233
|
+
assert.isTrue(transcript.steps[0].actual.media[0].downloadUri.endsWith('https://www.default.at/botium.png'))
|
|
234
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
235
|
+
})
|
|
205
236
|
})
|
|
206
237
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.compiler.convos[0].sourceTag.testSetId = 'testset3'
|
|
224
|
-
|
|
225
|
-
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
226
|
-
assert.equal(transcript.steps.length, 1)
|
|
227
|
-
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
228
|
-
assert.isTrue(transcript.steps[0].actual.media[0].downloadUri.endsWith('https://www.default.at/botium.png'))
|
|
229
|
-
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
230
|
-
})
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
describe('scripting.userinputs.mediaInputConvos.baseUrisCustomSelector', function () {
|
|
234
|
-
beforeEach(async function () {
|
|
235
|
-
const myCaps = {
|
|
236
|
-
[Capabilities.PROJECTNAME]: 'scripting.userinputs.mediaInputConvos',
|
|
237
|
-
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
238
|
-
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
239
|
-
[Capabilities.USER_INPUTS]: [
|
|
240
|
-
{
|
|
241
|
-
ref: 'MEDIA',
|
|
242
|
-
src: 'MediaInput',
|
|
243
|
-
args: {
|
|
244
|
-
baseUris: {
|
|
245
|
-
customval1: 'https://www.botium.at'
|
|
246
|
-
},
|
|
247
|
-
baseSelector: 'sourceTag.customField'
|
|
238
|
+
describe('baseUrisCustomSelector', function () {
|
|
239
|
+
beforeEach(async function () {
|
|
240
|
+
const myCaps = {
|
|
241
|
+
[Capabilities.PROJECTNAME]: 'scripting.userinputs.mediaInputConvos',
|
|
242
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
243
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
244
|
+
[Capabilities.USER_INPUTS]: [
|
|
245
|
+
{
|
|
246
|
+
ref: 'MEDIA',
|
|
247
|
+
src: 'MediaInput',
|
|
248
|
+
args: {
|
|
249
|
+
baseUris: {
|
|
250
|
+
customval1: 'https://www.botium.at'
|
|
251
|
+
},
|
|
252
|
+
baseSelector: 'sourceTag.customField'
|
|
253
|
+
}
|
|
248
254
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
const driver = new BotDriver(myCaps)
|
|
258
|
+
this.compiler = driver.BuildCompiler()
|
|
259
|
+
this.container = await driver.Build()
|
|
260
|
+
})
|
|
261
|
+
afterEach(async function () {
|
|
262
|
+
this.container && await this.container.Clean()
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
it('should add media from custom test set baseUri in user message', async function () {
|
|
266
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'media.convo.txt')
|
|
267
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
268
|
+
|
|
269
|
+
this.compiler.convos[0].sourceTag.customField = 'customval1'
|
|
270
|
+
|
|
271
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
272
|
+
assert.equal(transcript.steps.length, 1)
|
|
273
|
+
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
274
|
+
assert.equal(transcript.steps[0].actual.media[0].downloadUri, 'https://www.botium.at/botium.png')
|
|
275
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
276
|
+
})
|
|
255
277
|
})
|
|
256
|
-
afterEach(async function () {
|
|
257
|
-
this.container && await this.container.Clean()
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
it('should add media from custom test set baseUri in user message', async function () {
|
|
261
|
-
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'media.convo.txt')
|
|
262
|
-
assert.equal(this.compiler.convos.length, 1)
|
|
263
|
-
|
|
264
|
-
this.compiler.convos[0].sourceTag.customField = 'customval1'
|
|
265
|
-
|
|
266
|
-
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
267
|
-
assert.equal(transcript.steps.length, 1)
|
|
268
|
-
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
269
|
-
assert.equal(transcript.steps[0].actual.media[0].downloadUri, 'https://www.botium.at/botium.png')
|
|
270
|
-
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
271
|
-
})
|
|
272
|
-
})
|
|
273
278
|
|
|
274
|
-
describe('
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
279
|
+
describe('baseDir', function () {
|
|
280
|
+
beforeEach(async function () {
|
|
281
|
+
const myCaps = {
|
|
282
|
+
[Capabilities.PROJECTNAME]: 'scripting.userinputs.mediaInputConvos',
|
|
283
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
284
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
285
|
+
[Capabilities.USER_INPUTS]: [
|
|
286
|
+
{
|
|
287
|
+
ref: 'MEDIA',
|
|
288
|
+
src: 'MediaInput',
|
|
289
|
+
args: {
|
|
290
|
+
downloadMedia: true,
|
|
291
|
+
baseDir: path.join(__dirname, 'convos', 'files')
|
|
292
|
+
}
|
|
287
293
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const script = `should use dataUri as media in user message
|
|
294
|
+
]
|
|
295
|
+
}
|
|
296
|
+
const driver = new BotDriver(myCaps)
|
|
297
|
+
this.compiler = driver.BuildCompiler()
|
|
298
|
+
this.container = await driver.Build()
|
|
299
|
+
})
|
|
300
|
+
afterEach(async function () {
|
|
301
|
+
this.container && await this.container.Clean()
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
it('should expand media wc from baseDir in user message', async function () {
|
|
305
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'mediawcbasedir.convo.txt')
|
|
306
|
+
this.compiler.ExpandConvos()
|
|
307
|
+
assert.equal(this.compiler.convos.length, 3)
|
|
308
|
+
assert.equal(this.compiler.convos[0].conversation.length, 1)
|
|
309
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs.length, 1)
|
|
310
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].args[0], 'botium0.png')
|
|
311
|
+
assert.equal(this.compiler.convos[1].conversation[0].userInputs[0].args[0], 'botium1.png')
|
|
312
|
+
assert.equal(this.compiler.convos[2].conversation[0].userInputs[0].args[0], 'botium2.png')
|
|
313
|
+
|
|
314
|
+
await this.container.Start()
|
|
315
|
+
const transcript0 = await this.compiler.convos[0].Run(this.container)
|
|
316
|
+
assert.equal(transcript0.steps.length, 1)
|
|
317
|
+
assert.equal(transcript0.steps[0].actual.media.length, 1)
|
|
318
|
+
assert.isTrue(transcript0.steps[0].actual.media[0].downloadUri.endsWith('files/botium0.png'))
|
|
319
|
+
assert.equal(transcript0.steps[0].actual.media[0].mimeType, 'image/png')
|
|
320
|
+
await this.container.Stop()
|
|
321
|
+
|
|
322
|
+
await this.container.Start()
|
|
323
|
+
const transcript1 = await this.compiler.convos[1].Run(this.container)
|
|
324
|
+
assert.equal(transcript1.steps.length, 1)
|
|
325
|
+
assert.equal(transcript1.steps[0].actual.media.length, 1)
|
|
326
|
+
assert.isTrue(transcript1.steps[0].actual.media[0].downloadUri.endsWith('files/botium1.png'))
|
|
327
|
+
assert.equal(transcript1.steps[0].actual.media[0].mimeType, 'image/png')
|
|
328
|
+
await this.container.Stop()
|
|
329
|
+
|
|
330
|
+
await this.container.Start()
|
|
331
|
+
const transcript2 = await this.compiler.convos[2].Run(this.container)
|
|
332
|
+
assert.equal(transcript2.steps.length, 1)
|
|
333
|
+
assert.equal(transcript2.steps[0].actual.media.length, 1)
|
|
334
|
+
assert.isTrue(transcript2.steps[0].actual.media[0].downloadUri.endsWith('files/botium2.png'))
|
|
335
|
+
assert.equal(transcript2.steps[0].actual.media[0].mimeType, 'image/png')
|
|
336
|
+
await this.container.Stop()
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
it('should fail when media is out of baseDir', async function () {
|
|
340
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'mediaOutOfBasedir.convo.txt')
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
await this.compiler.convos[0].Run(this.container)
|
|
344
|
+
assert.fail('expected error')
|
|
345
|
+
} catch (err) {
|
|
346
|
+
assert.isTrue(err.message.startsWith('mediaoutofbasedir/Line 3: error sending to bot - The uri \'../*.png\' is pointing out of the base directory'))
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
it('should use dataUri as media in user message', async function () {
|
|
351
|
+
const mediaData = fs.readFileSync(path.resolve(__dirname, 'convos', 'files', 'botium0.png'))
|
|
352
|
+
const mediaUri = `data:image/png;base64,${mediaData.toString('base64')}`
|
|
353
|
+
const script = `should use dataUri as media in user message
|
|
349
354
|
|
|
350
355
|
#me
|
|
351
356
|
MEDIA ${mediaUri}
|
|
352
357
|
`
|
|
353
358
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
359
|
+
this.compiler.Compile(script, 'SCRIPTING_FORMAT_TXT', 'SCRIPTING_TYPE_CONVO')
|
|
360
|
+
assert.equal(this.compiler.convos.length, 1)
|
|
361
|
+
assert.equal(this.compiler.convos[0].conversation.length, 1)
|
|
362
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs.length, 1)
|
|
363
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].name, 'MEDIA')
|
|
364
|
+
assert.equal(this.compiler.convos[0].conversation[0].userInputs[0].args.length, 1)
|
|
365
|
+
assert.isTrue(this.compiler.convos[0].conversation[0].userInputs[0].args[0].startsWith('data:image/png'))
|
|
366
|
+
|
|
367
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
368
|
+
assert.equal(transcript.steps.length, 1)
|
|
369
|
+
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
370
|
+
assert.isTrue(transcript.steps[0].actual.media[0].downloadUri.startsWith('data:image/png'))
|
|
371
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
372
|
+
assert.isTrue(Buffer.isBuffer(transcript.steps[0].actual.media[0].buffer))
|
|
373
|
+
})
|
|
368
374
|
})
|
|
369
|
-
})
|
|
370
375
|
|
|
371
|
-
describe('
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
376
|
+
describe('mediaInputDownloadConvos.relative', function () {
|
|
377
|
+
beforeEach(async function () {
|
|
378
|
+
const myCaps = {
|
|
379
|
+
[Capabilities.PROJECTNAME]: 'scripting.userinputs.mediaInputDownloadConvos',
|
|
380
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
381
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
382
|
+
[Capabilities.USER_INPUTS]: [
|
|
383
|
+
{
|
|
384
|
+
ref: 'MEDIA',
|
|
385
|
+
src: 'MediaInput',
|
|
386
|
+
args: {
|
|
387
|
+
downloadMedia: true
|
|
388
|
+
}
|
|
383
389
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
390
|
+
]
|
|
391
|
+
}
|
|
392
|
+
const driver = new BotDriver(myCaps)
|
|
393
|
+
this.compiler = driver.BuildCompiler()
|
|
394
|
+
this.container = await driver.Build()
|
|
395
|
+
})
|
|
396
|
+
afterEach(async function () {
|
|
397
|
+
this.container && await this.container.Clean()
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
it('should add media buffer in user message', async function () {
|
|
401
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'media.convo.txt')
|
|
402
|
+
|
|
403
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
404
|
+
assert.equal(transcript.steps.length, 1)
|
|
405
|
+
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
406
|
+
assert.isTrue(transcript.steps[0].actual.media[0].downloadUri.endsWith('test/scripting/userinputs/convos/botium.png'))
|
|
407
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
408
|
+
assert.isTrue(Buffer.isBuffer(transcript.steps[0].actual.media[0].buffer))
|
|
409
|
+
})
|
|
404
410
|
})
|
|
405
|
-
})
|
|
406
411
|
|
|
407
|
-
describe('scripting.userinputs.mediaInputDownloadConvos.baseUri', function () {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
412
|
+
describe('scripting.userinputs.mediaInputDownloadConvos.baseUri', function () {
|
|
413
|
+
beforeEach(async function () {
|
|
414
|
+
const myCaps = {
|
|
415
|
+
[Capabilities.PROJECTNAME]: 'scripting.userinputs.mediaInputDownloadConvos',
|
|
416
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
417
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
418
|
+
[Capabilities.USER_INPUTS]: [
|
|
419
|
+
{
|
|
420
|
+
ref: 'MEDIA',
|
|
421
|
+
src: 'MediaInput',
|
|
422
|
+
args: {
|
|
423
|
+
downloadMedia: true,
|
|
424
|
+
baseUri: 'https://www.botium.at'
|
|
425
|
+
}
|
|
420
426
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
const driver = new BotDriver(myCaps)
|
|
430
|
+
this.compiler = driver.BuildCompiler()
|
|
431
|
+
this.container = await driver.Build()
|
|
432
|
+
})
|
|
433
|
+
afterEach(async function () {
|
|
434
|
+
this.container && await this.container.Clean()
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
it('should add media in user message', async function () {
|
|
438
|
+
const scope = nock('https://www.botium.at')
|
|
439
|
+
.get('/botium.png')
|
|
440
|
+
.reply(200, Buffer.from('hello world'))
|
|
441
|
+
.persist()
|
|
442
|
+
|
|
443
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'media.convo.txt')
|
|
444
|
+
|
|
445
|
+
const transcript = await this.compiler.convos[0].Run(this.container)
|
|
446
|
+
assert.equal(transcript.steps.length, 1)
|
|
447
|
+
assert.equal(transcript.steps[0].actual.media.length, 1)
|
|
448
|
+
assert.equal(transcript.steps[0].actual.media[0].downloadUri, 'https://www.botium.at/botium.png')
|
|
449
|
+
assert.equal(transcript.steps[0].actual.media[0].mimeType, 'image/png')
|
|
450
|
+
assert.isTrue(Buffer.isBuffer(transcript.steps[0].actual.media[0].buffer))
|
|
451
|
+
|
|
452
|
+
scope.persist(false)
|
|
453
|
+
})
|
|
448
454
|
})
|
|
449
455
|
})
|