botium-core 1.14.1 → 1.14.4

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.
Files changed (39) hide show
  1. package/dist/botium-cjs.js +341 -126
  2. package/dist/botium-cjs.js.map +1 -1
  3. package/dist/botium-es.js +359 -144
  4. package/dist/botium-es.js.map +1 -1
  5. package/package.json +11 -11
  6. package/src/Capabilities.js +2 -0
  7. package/src/scripting/BotiumError.js +40 -3
  8. package/src/scripting/CompilerMarkdown.js +2 -1
  9. package/src/scripting/CompilerTxt.js +1 -4
  10. package/src/scripting/Convo.js +113 -19
  11. package/src/scripting/MatchFunctions.js +30 -8
  12. package/src/scripting/ScriptingMemory.js +7 -0
  13. package/src/scripting/ScriptingProvider.js +87 -36
  14. package/src/scripting/helper.js +3 -2
  15. package/src/scripting/logichook/LogicHookConsts.js +5 -2
  16. package/src/scripting/logichook/LogicHookUtils.js +8 -6
  17. package/src/scripting/logichook/logichooks/ConvoStepParametersLogicHook.js +6 -0
  18. package/src/scripting/logichook/logichooks/OrderedListToButtonLogicHook.js +37 -0
  19. package/test/compiler/compilermarkdown.spec.js +3 -3
  20. package/test/compiler/compilertxt.spec.js +1 -1
  21. package/test/compiler/convos/txt/convos_emptyrow_just_emptyrow.convo.txt +1 -1
  22. package/test/convo/fillAndApplyScriptingMemory.spec.js +11 -0
  23. package/test/logichooks/orderedListToButton.spec.js +35 -0
  24. package/test/scripting/asserters/convoStepParameters.spec.js +151 -0
  25. package/test/scripting/asserters/convos/TEXT_GOOD.convo.txt +6 -0
  26. package/test/scripting/asserters/convos/convo_step_parameter_matchmode_failed.convo.txt +8 -0
  27. package/test/scripting/asserters/convos/convo_step_parameter_matchmode_failed_wer.convo.txt +9 -0
  28. package/test/scripting/asserters/convos/convo_step_parameter_retry_asserters_all_good.convo.txt +9 -0
  29. package/test/scripting/asserters/convos/convo_step_parameter_retry_asserters_botium_timeout.convo.txt +9 -0
  30. package/test/scripting/asserters/convos/convo_step_parameter_retry_asserters_good.convo.txt +9 -0
  31. package/test/scripting/asserters/convos/convo_step_parameter_retry_asserters_good_global.convo.txt +9 -0
  32. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_and_asserter.convo.txt +10 -0
  33. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_botium_timeout.convo.txt +9 -0
  34. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_but_no_button.convo.txt +10 -0
  35. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_good.convo.txt +9 -0
  36. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_good_begin.convo.txt +11 -0
  37. package/test/scripting/logichooks/convos/scripting_memory_overwrite_and_check.convo.txt +2 -2
  38. package/test/scripting/matching/matchingmode.spec.js +4 -1
  39. package/test/scripting/scriptingProvider.spec.js +38 -12
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_matchmode_failed_wer
2
+
3
+ #me
4
+ Hello1
5
+
6
+ #bot
7
+ You said Hello1 Hello2 Hello3 Hello4
8
+ CONVO_STEP_PARAMETERS {"matchingMode":"wer","matchingModeWer":25}
9
+
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_asserters_good
2
+
3
+ #me
4
+ Hello
5
+ Button
6
+
7
+ #bot
8
+ BUTTONS button1|button2
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "allAsserters": true}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_asserters_good
2
+
3
+ #me
4
+ Hello
5
+ Button
6
+
7
+ #bot
8
+ BUTTONS button1|buttonXXXXXX
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "asserters": ["BUTTONS"]}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_asserters_good
2
+
3
+ #me
4
+ Hello
5
+ Button
6
+
7
+ #bot
8
+ BUTTONS button1|button2
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "asserters": ["BUTTONS"]}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_asserters_good_global
2
+
3
+
4
+ #me
5
+ Hello1
6
+ Intent
7
+
8
+ #bot
9
+ INTENT someIntent
@@ -0,0 +1,10 @@
1
+ convo_step_parameter_retry_main_and_asserter
2
+
3
+ #me
4
+ Butt
5
+ Button
6
+
7
+ #bot
8
+ You said Butt
9
+ BUTTONS button1|button2
10
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "mainAsserter": true, "allAsserters": true}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_main_botium_timeout
2
+
3
+ #me
4
+ Hello1
5
+ Hello2
6
+
7
+ #bot
8
+ You said Hello3
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "mainAsserter": true}}
@@ -0,0 +1,10 @@
1
+ convo_step_parameter_retry_main_but_no_button
2
+
3
+ #me
4
+ Hello1
5
+ Hello2
6
+
7
+ #bot
8
+ You said Hello2
9
+ BUTTONS some not existing button
10
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "mainAsserter": true}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_main_good
2
+
3
+ #me
4
+ Hello1
5
+ Hello2
6
+
7
+ #bot
8
+ You said Hello2
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 201, "mainAsserter": true}}
@@ -0,0 +1,11 @@
1
+ convo_step_parameter_retry_main_good_begin
2
+
3
+ #begin
4
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "mainAsserter": true}}
5
+
6
+ #me
7
+ Hello1
8
+ Hello2
9
+
10
+ #bot
11
+ You said Hello2
@@ -7,7 +7,7 @@ this is a variable: VARVALUE1
7
7
  this is a variable: $myvar
8
8
 
9
9
  #me
10
- this is a variable: VARVALUE2
10
+ this is a variable: VARVALUE2
11
11
 
12
12
  #bot
13
- this is a variable: $myvar
13
+ this is a variable: $myvar
@@ -207,7 +207,10 @@ describe('scripting.matching.matchingmode', function () {
207
207
  'umm',
208
208
  'interesting',
209
209
  'really?'
210
- ], 'test')
210
+ ],
211
+ 'test',
212
+ null,
213
+ {})
211
214
  })
212
215
  })
213
216
 
@@ -5,6 +5,7 @@ const { Convo } = require('../../src/scripting/Convo')
5
5
  const ScriptingProvider = require('../../src/scripting/ScriptingProvider')
6
6
  const DefaultCapabilities = require('../../src/Defaults').Capabilities
7
7
  const Capabilities = require('../../src/Capabilities')
8
+ const { LOGIC_HOOK_EVENTS } = require('../../src/scripting/logichook/LogicHookConsts')
8
9
 
9
10
  describe('scripting.scriptingProvider', function () {
10
11
  describe('ReadScriptsFromDirectory', function () {
@@ -65,7 +66,7 @@ describe('scripting.scriptingProvider', function () {
65
66
  assert.equal(tomatch.length, 2)
66
67
  assert.equal(tomatch[0], 'TEXT1')
67
68
  assert.equal(tomatch[1], 'TEXT2')
68
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1')
69
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1', null, {})
69
70
  })
70
71
  it('should resolve multiple utterance', async function () {
71
72
  const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
@@ -85,7 +86,7 @@ describe('scripting.scriptingProvider', function () {
85
86
  assert.equal(tomatchUtt1.length, 2)
86
87
  assert.equal(tomatchUtt1[0], 'TEXT1')
87
88
  assert.equal(tomatchUtt1[1], 'TEXT2')
88
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatchUtt1, 'test1')
89
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatchUtt1, 'test1', null, {})
89
90
  const tomatchUtt2 = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt2' })
90
91
  assert.isArray(tomatchUtt2)
91
92
  assert.equal(tomatchUtt2.length, 2)
@@ -121,7 +122,7 @@ describe('scripting.scriptingProvider', function () {
121
122
  assert.equal(tomatch.length, 1)
122
123
  assert.equal(tomatch[0], 'utt2')
123
124
  try {
124
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1')
125
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1', null, {})
125
126
  assert.fail('expected error')
126
127
  } catch (err) {
127
128
  assert.isTrue(err.message.indexOf('Bot response') > 0)
@@ -141,7 +142,7 @@ describe('scripting.scriptingProvider', function () {
141
142
  utterances: ['TEXT1', 'TEXT2']
142
143
  })
143
144
  try {
144
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', 'utt1', 'test1')
145
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', 'utt1', 'test1', null, {})
145
146
  assert.fail('expected error')
146
147
  } catch (err) {
147
148
  assert.isTrue(err.message.indexOf('Bot response') > 0)
@@ -166,7 +167,7 @@ describe('scripting.scriptingProvider', function () {
166
167
  assert.equal(tomatch.length, 2)
167
168
  assert.equal(tomatch[0], 'TEXT1 hello')
168
169
  assert.equal(tomatch[1], 'TEXT2 hello')
169
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1')
170
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1', null, {})
170
171
  })
171
172
  it('should resolve and append utterance args', async function () {
172
173
  const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
@@ -182,7 +183,7 @@ describe('scripting.scriptingProvider', function () {
182
183
  assert.equal(tomatch.length, 2)
183
184
  assert.equal(tomatch[0], 'TEXT1 hello')
184
185
  assert.equal(tomatch[1], 'TEXT2 hello')
185
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1')
186
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1', null, {})
186
187
  })
187
188
 
188
189
  describe('should resolve utterance with ambiguous scripting memory variable (with a debug message)', function () {
@@ -909,7 +910,7 @@ describe('scripting.scriptingProvider', function () {
909
910
  await scriptingProvider.Build()
910
911
  const scriptingContext = scriptingProvider._buildScriptContext()
911
912
  try {
912
- scriptingContext.scriptingEvents.assertBotResponse('actual', 'expected', 'test1')
913
+ scriptingContext.scriptingEvents.assertBotResponse('actual', 'expected', 'test1', null, {})
913
914
  assert.fail('expected error')
914
915
  } catch (err) {
915
916
  assert.equal(err.message, 'test1: Bot response "actual" expected to match "expected"')
@@ -920,7 +921,7 @@ describe('scripting.scriptingProvider', function () {
920
921
  await scriptingProvider.Build()
921
922
  const scriptingContext = scriptingProvider._buildScriptContext()
922
923
  try {
923
- scriptingContext.scriptingEvents.assertBotResponse(null, 'expected', 'test1')
924
+ scriptingContext.scriptingEvents.assertBotResponse(null, 'expected', 'test1', null, {})
924
925
  assert.fail('expected error')
925
926
  } catch (err) {
926
927
  assert.equal(err.message, 'test1: Bot response <no response> expected to match "expected"')
@@ -931,7 +932,7 @@ describe('scripting.scriptingProvider', function () {
931
932
  await scriptingProvider.Build()
932
933
  const scriptingContext = scriptingProvider._buildScriptContext()
933
934
  try {
934
- scriptingContext.scriptingEvents.assertBotResponse('actual', ['expected1', 'expected2'], 'test1')
935
+ scriptingContext.scriptingEvents.assertBotResponse('actual', ['expected1', 'expected2'], 'test1', null, {})
935
936
  assert.fail('expected error')
936
937
  } catch (err) {
937
938
  assert.equal(err.message, 'test1: Bot response "actual" expected to match one of "expected1", "expected2"')
@@ -945,7 +946,7 @@ describe('scripting.scriptingProvider', function () {
945
946
  await scriptingProvider.Build()
946
947
  const scriptingContext = scriptingProvider._buildScriptContext()
947
948
  try {
948
- scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', ['Keine Antwort gefunden'], 'test1')
949
+ scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', ['Keine Antwort gefunden'], 'test1', null, {})
949
950
  assert.fail('expected error')
950
951
  } catch (err) {
951
952
  assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match "Keine Antwort gefunden"')
@@ -956,7 +957,7 @@ describe('scripting.scriptingProvider', function () {
956
957
  await scriptingProvider.Build()
957
958
  const scriptingContext = scriptingProvider._buildScriptContext()
958
959
  try {
959
- scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', [''], 'test1')
960
+ scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', [''], 'test1', null, {})
960
961
  assert.fail('expected error')
961
962
  } catch (err) {
962
963
  assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match <any response>')
@@ -967,11 +968,36 @@ describe('scripting.scriptingProvider', function () {
967
968
  await scriptingProvider.Build()
968
969
  const scriptingContext = scriptingProvider._buildScriptContext()
969
970
  try {
970
- scriptingContext.scriptingEvents.assertBotNotResponse('', [''], 'test1')
971
+ scriptingContext.scriptingEvents.assertBotNotResponse('', [''], 'test1', null, {})
971
972
  assert.fail('expected error')
972
973
  } catch (err) {
973
974
  assert.equal(err.message, 'test1: Bot response <no response> expected NOT to match <any response>')
974
975
  }
975
976
  })
976
977
  })
978
+
979
+ describe('should call logichooks and userinputs even if there is no convo (logichook from livechat, and crawler)', function () {
980
+ LOGIC_HOOK_EVENTS.forEach(async (eventName) => {
981
+ it(`Logichook, event: ${eventName}`, async function () {
982
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, {
983
+ [Capabilities.LOGIC_HOOKS]: [{
984
+ ref: 'SET_TEXT_FROM_HOOK',
985
+ src: {
986
+ [eventName]: ({ someobject, args }) => {
987
+ someobject.testAttribute = 'testAttributeValue'
988
+ }
989
+ },
990
+ global: true
991
+ }]
992
+ }))
993
+ await scriptingProvider.Build()
994
+ const scriptingContext = scriptingProvider._buildScriptContext()
995
+ const someobject = {}
996
+ await scriptingContext.scriptingEvents[eventName]({
997
+ someobject
998
+ })
999
+ assert.equal(someobject.testAttribute, 'testAttributeValue')
1000
+ })
1001
+ })
1002
+ })
977
1003
  })