botium-core 1.14.10 → 1.15.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/dist/botium-cjs.js +216 -115
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +215 -114
- package/dist/botium-es.js.map +1 -1
- package/package.json +4 -4
- package/samples/connectors/simplerest-async/jokebot.js +24 -18
- package/src/Capabilities.js +3 -0
- package/src/containers/BaseContainer.js +1 -2
- package/src/containers/plugins/SimpleRestContainer.js +158 -89
- package/src/scripting/Convo.js +2 -2
- package/src/scripting/helper.js +59 -22
- package/src/scripting/logichook/asserter/BaseTextAsserter.js +1 -2
- package/src/scripting/logichook/asserter/ButtonsAsserter.js +3 -4
- package/src/scripting/logichook/userinput/MediaInput.js +14 -17
- package/test/compiler/compilertxt.spec.js +18 -0
- package/test/compiler/convos/txt/convos_jsonmessage.convo.txt +10 -0
- package/test/connectors/simplerest.spec.js +290 -42
- package/test/hooks/customhooks.spec.js +3 -5
- package/test/scripting/helper.spec.js +21 -0
- package/test/scripting/scriptingProvider.spec.js +34 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const Capabilities = require('../../index').Capabilities
|
|
2
|
+
const { normalizeText } = require('../../src/scripting/helper')
|
|
3
|
+
const assert = require('chai').assert
|
|
4
|
+
|
|
5
|
+
describe('scripting.helper', function () {
|
|
6
|
+
describe('NormalizeText', function () {
|
|
7
|
+
it('Basic', async function () {
|
|
8
|
+
assert.equal(normalizeText('Hello! <br>And this is the body!!!', { [Capabilities.SCRIPTING_NORMALIZE_TEXT]: true }), 'Hello! And this is the body!!!')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('Remove specific characters', async function () {
|
|
12
|
+
// (,/,, +,-,//) -> ([",", "+", "-", "/"])
|
|
13
|
+
assert.equal(normalizeText('Hello,!+-/ <br>And this is the body!!!', { [Capabilities.SCRIPTING_NORMALIZE_TEXT_REMOVE_CHARACTERES]: ',/,, +,-,//' }), 'Hello! <br>And this is the body!!!')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('Remove characters via multilang regex', async function () {
|
|
17
|
+
// remove all emojis, currency symbols, and "`" character
|
|
18
|
+
assert.equal(normalizeText('A ticket` to 大阪 costs ¥2000👌.', { [Capabilities.SCRIPTING_NORMALIZE_TEXT_REMOVE_REGEXP]: '[\\p{Emoji_Presentation}\\p{Currency_Symbol}`]' }), 'A ticket to 大阪 costs 2000.')
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
})
|
|
@@ -17,6 +17,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
17
17
|
assert.isArray(convos)
|
|
18
18
|
assert.equal(convos.length, 2)
|
|
19
19
|
})
|
|
20
|
+
|
|
20
21
|
it('should read multiple files from dir with globFilter', async function () {
|
|
21
22
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
22
23
|
await scriptingProvider.Build()
|
|
@@ -25,6 +26,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
25
26
|
assert.isArray(convos)
|
|
26
27
|
assert.equal(convos.length, 2)
|
|
27
28
|
})
|
|
29
|
+
|
|
28
30
|
it('should ignore files from dir with globFilter', async function () {
|
|
29
31
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
30
32
|
await scriptingProvider.Build()
|
|
@@ -33,6 +35,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
33
35
|
assert.isArray(convos)
|
|
34
36
|
assert.equal(convos.length, 0)
|
|
35
37
|
})
|
|
38
|
+
|
|
36
39
|
it('should read single file from file path', async function () {
|
|
37
40
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
38
41
|
await scriptingProvider.Build()
|
|
@@ -41,6 +44,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
41
44
|
assert.isArray(convos)
|
|
42
45
|
assert.equal(convos.length, 1)
|
|
43
46
|
})
|
|
47
|
+
|
|
44
48
|
it('should skip convos', async function () {
|
|
45
49
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
46
50
|
await scriptingProvider.Build()
|
|
@@ -68,6 +72,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
68
72
|
assert.equal(tomatch[1], 'TEXT2')
|
|
69
73
|
scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1', null, {})
|
|
70
74
|
})
|
|
75
|
+
|
|
71
76
|
it('should resolve multiple utterance', async function () {
|
|
72
77
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
73
78
|
await scriptingProvider.Build()
|
|
@@ -93,6 +98,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
93
98
|
assert.equal(tomatchUtt2[0], 'TEXT3')
|
|
94
99
|
assert.equal(tomatchUtt2[1], 'TEXT4')
|
|
95
100
|
})
|
|
101
|
+
|
|
96
102
|
it('should resolve null on invalid utterance', async function () {
|
|
97
103
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
98
104
|
await scriptingProvider.Build()
|
|
@@ -108,6 +114,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
108
114
|
})
|
|
109
115
|
assert.isNull(tomatch)
|
|
110
116
|
})
|
|
117
|
+
|
|
111
118
|
it('should fail on invalid utterance', async function () {
|
|
112
119
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
113
120
|
await scriptingProvider.Build()
|
|
@@ -133,6 +140,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
133
140
|
assert.equal(err.context.cause.actual, 'TEXT1')
|
|
134
141
|
}
|
|
135
142
|
})
|
|
143
|
+
|
|
136
144
|
it('should fail on unresolved utterance', async function () {
|
|
137
145
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
138
146
|
await scriptingProvider.Build()
|
|
@@ -153,6 +161,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
153
161
|
assert.equal(err.context.cause.actual, 'TEXT1')
|
|
154
162
|
}
|
|
155
163
|
})
|
|
164
|
+
|
|
156
165
|
it('should resolve and format utterance args', async function () {
|
|
157
166
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
158
167
|
await scriptingProvider.Build()
|
|
@@ -169,6 +178,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
169
178
|
assert.equal(tomatch[1], 'TEXT2 hello')
|
|
170
179
|
scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1', null, {})
|
|
171
180
|
})
|
|
181
|
+
|
|
172
182
|
it('should resolve and append utterance args', async function () {
|
|
173
183
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
174
184
|
await scriptingProvider.Build()
|
|
@@ -246,6 +256,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
246
256
|
const scriptingProvider = new ScriptingProvider()
|
|
247
257
|
assert.equal(scriptingProvider._isValidAsserterType('assertConvoStep'), true)
|
|
248
258
|
})
|
|
259
|
+
|
|
249
260
|
it('invalid asserterType', async function () {
|
|
250
261
|
const scriptingProvider = new ScriptingProvider()
|
|
251
262
|
assert.equal(scriptingProvider._isValidAsserterType('assertStep'), false)
|
|
@@ -294,6 +305,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
294
305
|
assert.equal(scriptingProvider.convos[1].header.name, 'test convo/utt1-L2')
|
|
295
306
|
assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
|
|
296
307
|
})
|
|
308
|
+
|
|
297
309
|
it('should build convos for utterance using iterator', async function () {
|
|
298
310
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
299
311
|
await scriptingProvider.Build()
|
|
@@ -336,6 +348,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
336
348
|
// assert.deepEqual(iteratedConvo, expected[index])
|
|
337
349
|
// })
|
|
338
350
|
})
|
|
351
|
+
|
|
339
352
|
it('should build convos for utterance with parameters', async function () {
|
|
340
353
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
341
354
|
await scriptingProvider.Build()
|
|
@@ -364,6 +377,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
364
377
|
assert.equal(scriptingProvider.convos[1].header.name, 'test convo/utt1-L2')
|
|
365
378
|
assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2 arg0 1')
|
|
366
379
|
})
|
|
380
|
+
|
|
367
381
|
it('should build convos for utterance with whitespace', async function () {
|
|
368
382
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
369
383
|
await scriptingProvider.Build()
|
|
@@ -392,6 +406,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
392
406
|
assert.equal(scriptingProvider.convos[1].header.name, 'test convo/utt with some whitespace-L2')
|
|
393
407
|
assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
|
|
394
408
|
})
|
|
409
|
+
|
|
395
410
|
describe('should build convos for SCRIPTING_UTTEXPANSION_NAMING_MODE', function () {
|
|
396
411
|
const utterances = [
|
|
397
412
|
{
|
|
@@ -442,6 +457,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
442
457
|
assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1-TEXT1 0123456...')
|
|
443
458
|
assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2-TEXT2 0123456...')
|
|
444
459
|
})
|
|
460
|
+
|
|
445
461
|
it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance len=1', async function () {
|
|
446
462
|
const scriptingProvider = new ScriptingProvider(Object.assign(
|
|
447
463
|
{},
|
|
@@ -474,6 +490,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
474
490
|
assert.equal(scriptingProvider.convos[0].conversation.length, 1)
|
|
475
491
|
assert.equal(scriptingProvider.convos[0].header.name, 'test convo')
|
|
476
492
|
})
|
|
493
|
+
|
|
477
494
|
it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance, turn length off', async function () {
|
|
478
495
|
const scriptingProvider = new ScriptingProvider(Object.assign(
|
|
479
496
|
{},
|
|
@@ -513,6 +530,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
513
530
|
assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1-TEXT1 0...')
|
|
514
531
|
assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2-TEXT2 0...')
|
|
515
532
|
})
|
|
533
|
+
|
|
516
534
|
it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance userinputs', async function () {
|
|
517
535
|
const scriptingProvider = new ScriptingProvider(Object.assign(
|
|
518
536
|
{},
|
|
@@ -551,6 +569,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
551
569
|
assert.equal(scriptingProvider.convos[1].header.name, 'test convo/MEDIA-L2-test2 0123456...')
|
|
552
570
|
assert.equal(scriptingProvider.convos[2].header.name, 'test convo/MEDIA-L3-test3.jpg')
|
|
553
571
|
})
|
|
572
|
+
|
|
554
573
|
it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance userinputs len=1', async function () {
|
|
555
574
|
const scriptingProvider = new ScriptingProvider(Object.assign(
|
|
556
575
|
{},
|
|
@@ -587,6 +606,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
587
606
|
assert.equal(scriptingProvider.convos[0].conversation.length, 1)
|
|
588
607
|
assert.equal(scriptingProvider.convos[0].header.name, 'test convo')
|
|
589
608
|
})
|
|
609
|
+
|
|
590
610
|
it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance userinputs and utterances', async function () {
|
|
591
611
|
const scriptingProvider = new ScriptingProvider(Object.assign(
|
|
592
612
|
{},
|
|
@@ -630,6 +650,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
630
650
|
assert.equal(scriptingProvider.convos[4].header.name, 'test convo/uttText-L2-TEXT2 0123456...')
|
|
631
651
|
})
|
|
632
652
|
})
|
|
653
|
+
|
|
633
654
|
describe('should have be possible to generate / store convos partially', function () {
|
|
634
655
|
const _createConvos = async () => {
|
|
635
656
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
@@ -720,6 +741,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
720
741
|
assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
|
|
721
742
|
assert.equal(scriptingProvider.convos[1].toString(), '2 utt1/utt1-L00002 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT2 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
|
|
722
743
|
}).timeout(5000)
|
|
744
|
+
|
|
723
745
|
it('should build incomprehension convos for utterance', async function () {
|
|
724
746
|
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'INCOMPREHENSION' }))
|
|
725
747
|
await scriptingProvider.Build()
|
|
@@ -750,6 +772,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
750
772
|
assert.equal(scriptingProvider.convos[1].conversation[1].messageText, 'INCOMPREHENSION')
|
|
751
773
|
assert.equal(scriptingProvider.convos[1].conversation[1].not, true)
|
|
752
774
|
})
|
|
775
|
+
|
|
753
776
|
it('should build intent check convos for utterance', async function () {
|
|
754
777
|
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_USENAMEASINTENT: true }))
|
|
755
778
|
await scriptingProvider.Build()
|
|
@@ -779,6 +802,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
779
802
|
assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].name, 'INTENT')
|
|
780
803
|
assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].args[0], 'utt1')
|
|
781
804
|
})
|
|
805
|
+
|
|
782
806
|
it('should build intent check convos for utterance (with arg)', async function () {
|
|
783
807
|
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
784
808
|
await scriptingProvider.Build()
|
|
@@ -808,6 +832,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
808
832
|
assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].name, 'INTENT')
|
|
809
833
|
assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].args[0], 'utt1')
|
|
810
834
|
})
|
|
835
|
+
|
|
811
836
|
it('should build check-only convos for utterance', async function () {
|
|
812
837
|
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
813
838
|
await scriptingProvider.Build()
|
|
@@ -834,6 +859,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
834
859
|
assert.equal(scriptingProvider.convos[1].conversation[1].messageText, '')
|
|
835
860
|
assert.isFalse(scriptingProvider.convos[1].conversation[1].not)
|
|
836
861
|
})
|
|
862
|
+
|
|
837
863
|
it('should fail incomprehension convos for utterance without incomprehension utt', async function () {
|
|
838
864
|
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'INCOMPREHENSION' }))
|
|
839
865
|
await scriptingProvider.Build()
|
|
@@ -845,6 +871,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
845
871
|
assert.isTrue(err.message.indexOf('incomprehension utterance \'INCOMPREHENSION\' undefined') > 0)
|
|
846
872
|
}
|
|
847
873
|
})
|
|
874
|
+
|
|
848
875
|
it('should add incomprehension utterances to new utterance list', async function () {
|
|
849
876
|
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
850
877
|
await scriptingProvider.Build()
|
|
@@ -856,6 +883,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
856
883
|
scriptingProvider.ExpandUtterancesToConvos({ incomprehensionUtt: 'INCOMPREHENSION', incomprehensionUtts: ['INCOMPREHENSION3', 'INCOMPREHENSION4'] })
|
|
857
884
|
assert.lengthOf(scriptingProvider.utterances.INCOMPREHENSION.utterances, 2)
|
|
858
885
|
})
|
|
886
|
+
|
|
859
887
|
it('should add incomprehension utterances to new default utterance list', async function () {
|
|
860
888
|
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
861
889
|
await scriptingProvider.Build()
|
|
@@ -867,6 +895,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
867
895
|
scriptingProvider.ExpandUtterancesToConvos({ incomprehensionUtts: ['INCOMPREHENSION3', 'INCOMPREHENSION4'] })
|
|
868
896
|
assert.lengthOf(scriptingProvider.utterances.UTT_INCOMPREHENSION.utterances, 2)
|
|
869
897
|
})
|
|
898
|
+
|
|
870
899
|
it('should add incomprehension utterances to existing utterance list', async function () {
|
|
871
900
|
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
872
901
|
await scriptingProvider.Build()
|
|
@@ -882,6 +911,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
882
911
|
scriptingProvider.ExpandUtterancesToConvos({ incomprehensionUtt: 'INCOMPREHENSION', incomprehensionUtts: ['INCOMPREHENSION3', 'INCOMPREHENSION4'] })
|
|
883
912
|
assert.lengthOf(scriptingProvider.utterances.INCOMPREHENSION.utterances, 4)
|
|
884
913
|
})
|
|
914
|
+
|
|
885
915
|
it('should add incomprehension intent to asserter list', async function () {
|
|
886
916
|
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
887
917
|
await scriptingProvider.Build()
|
|
@@ -916,6 +946,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
916
946
|
assert.equal(err.message, 'test1: Bot response "actual" expected to match "expected"')
|
|
917
947
|
}
|
|
918
948
|
})
|
|
949
|
+
|
|
919
950
|
it('should fail with correct error message on empty bot message', async function () {
|
|
920
951
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
921
952
|
await scriptingProvider.Build()
|
|
@@ -927,6 +958,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
927
958
|
assert.equal(err.message, 'test1: Bot response <no response> expected to match "expected"')
|
|
928
959
|
}
|
|
929
960
|
})
|
|
961
|
+
|
|
930
962
|
it('should fail with correct error message on multiple tomatch', async function () {
|
|
931
963
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
932
964
|
await scriptingProvider.Build()
|
|
@@ -952,6 +984,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
952
984
|
assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match "Keine Antwort gefunden"')
|
|
953
985
|
}
|
|
954
986
|
})
|
|
987
|
+
|
|
955
988
|
it('should fail with correct error message on by empty asserter', async function () {
|
|
956
989
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
957
990
|
await scriptingProvider.Build()
|
|
@@ -963,6 +996,7 @@ describe('scripting.scriptingProvider', function () {
|
|
|
963
996
|
assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match <any response>')
|
|
964
997
|
}
|
|
965
998
|
})
|
|
999
|
+
|
|
966
1000
|
it('should fail with correct error message on by empty asserter, and empty bot response', async function () {
|
|
967
1001
|
const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
|
|
968
1002
|
await scriptingProvider.Build()
|