botium-core 1.13.3 → 1.13.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.
- package/dist/botium-cjs.js +74 -26
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +74 -26
- package/dist/botium-es.js.map +1 -1
- package/package.json +1 -1
- package/src/Capabilities.js +2 -0
- package/src/Defaults.js +4 -0
- package/src/mocks/BotiumMockScripting.js +1 -0
- package/src/scripting/ScriptingProvider.js +56 -32
- package/test/scripting/scriptingProvider.spec.js +57 -0
package/package.json
CHANGED
package/src/Capabilities.js
CHANGED
|
@@ -133,6 +133,8 @@ module.exports = {
|
|
|
133
133
|
SCRIPTING_UTTEXPANSION_MODE: 'SCRIPTING_UTTEXPANSION_MODE',
|
|
134
134
|
SCRIPTING_UTTEXPANSION_RANDOM_COUNT: 'SCRIPTING_UTTEXPANSION_RANDOM_COUNT',
|
|
135
135
|
SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'SCRIPTING_UTTEXPANSION_INCOMPREHENSION',
|
|
136
|
+
SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS: 'SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS',
|
|
137
|
+
SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS: 'SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS',
|
|
136
138
|
SCRIPTING_UTTEXPANSION_USENAMEASINTENT: 'SCRIPTING_UTTEXPANSION_USENAMEASINTENT',
|
|
137
139
|
// justLineTag, utterance
|
|
138
140
|
SCRIPTING_UTTEXPANSION_NAMING_MODE: 'SCRIPTING_UTTEXPANSION_NAMING_MODE',
|
package/src/Defaults.js
CHANGED
|
@@ -49,6 +49,10 @@ module.exports = {
|
|
|
49
49
|
[Capabilities.SCRIPTING_UTTEXPANSION_RANDOM_COUNT]: 1,
|
|
50
50
|
[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'justLineTag',
|
|
51
51
|
[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX]: '16',
|
|
52
|
+
[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSION]: null,
|
|
53
|
+
[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS]: [],
|
|
54
|
+
[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS]: [],
|
|
55
|
+
[Capabilities.SCRIPTING_UTTEXPANSION_USENAMEASINTENT]: false,
|
|
52
56
|
[Capabilities.SCRIPTING_MEMORYEXPANSION_KEEP_ORIG]: false,
|
|
53
57
|
[Capabilities.SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS]: false,
|
|
54
58
|
[Capabilities.SCRIPTING_FORCE_BOT_CONSUMED]: false,
|
|
@@ -770,31 +770,79 @@ module.exports = class ScriptingProvider {
|
|
|
770
770
|
this._sortConvos()
|
|
771
771
|
}
|
|
772
772
|
|
|
773
|
-
ExpandUtterancesToConvos ({ useNameAsIntent, incomprehensionUtt } = {}) {
|
|
773
|
+
ExpandUtterancesToConvos ({ useNameAsIntent, incomprehensionIntents, incomprehensionUtts, incomprehensionUtt } = {}) {
|
|
774
774
|
const expandedConvos = []
|
|
775
775
|
|
|
776
776
|
if (_.isUndefined(useNameAsIntent)) {
|
|
777
777
|
useNameAsIntent = !!this.caps[Capabilities.SCRIPTING_UTTEXPANSION_USENAMEASINTENT]
|
|
778
778
|
}
|
|
779
|
+
if (_.isUndefined(incomprehensionIntents)) {
|
|
780
|
+
incomprehensionIntents = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONINTENTS]
|
|
781
|
+
}
|
|
782
|
+
if (_.isUndefined(incomprehensionUtts)) {
|
|
783
|
+
incomprehensionUtts = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSIONUTTS]
|
|
784
|
+
}
|
|
779
785
|
if (_.isUndefined(incomprehensionUtt)) {
|
|
780
786
|
incomprehensionUtt = this.caps[Capabilities.SCRIPTING_UTTEXPANSION_INCOMPREHENSION]
|
|
781
787
|
}
|
|
782
788
|
|
|
783
|
-
if (
|
|
784
|
-
throw new Error(
|
|
789
|
+
if (incomprehensionUtt && (!incomprehensionUtts || incomprehensionUtts.length === 0) && !this.utterances[incomprehensionUtt]) {
|
|
790
|
+
throw new Error(`ExpandUtterancesToConvos - incomprehension utterance '${incomprehensionUtt}' undefined (and no user examples given)`)
|
|
785
791
|
}
|
|
786
|
-
if (
|
|
787
|
-
|
|
792
|
+
if (incomprehensionUtts && incomprehensionUtts.length > 0) {
|
|
793
|
+
if (!incomprehensionUtt) {
|
|
794
|
+
incomprehensionUtt = 'UTT_INCOMPREHENSION'
|
|
795
|
+
}
|
|
796
|
+
if (this.utterances[incomprehensionUtt]) {
|
|
797
|
+
this.utterances[incomprehensionUtt].utterances.push(...incomprehensionUtts)
|
|
798
|
+
} else {
|
|
799
|
+
this.utterances[incomprehensionUtt] = {
|
|
800
|
+
name: incomprehensionUtt,
|
|
801
|
+
utterances: [...incomprehensionUtts]
|
|
802
|
+
}
|
|
803
|
+
}
|
|
788
804
|
}
|
|
789
805
|
|
|
790
806
|
if (useNameAsIntent) {
|
|
791
807
|
debug('ExpandUtterancesToConvos - Using utterance name as NLU intent')
|
|
792
|
-
}
|
|
793
|
-
|
|
808
|
+
}
|
|
809
|
+
if (incomprehensionIntents && incomprehensionIntents.length > 0) {
|
|
810
|
+
debug(`ExpandUtterancesToConvos - Using ${incomprehensionIntents.length} incomprehension NLU intent(s)`)
|
|
811
|
+
}
|
|
812
|
+
if (incomprehensionUtt) {
|
|
813
|
+
debug(`ExpandUtterancesToConvos - Using incomprehension utterance expansion mode: ${incomprehensionUtt}, ${this.utterances[incomprehensionUtt].utterances.length} user example(s)`)
|
|
794
814
|
}
|
|
795
815
|
|
|
796
816
|
_.keys(this.utterances).filter(u => u !== incomprehensionUtt).forEach(uttName => {
|
|
797
817
|
const utt = this.utterances[uttName]
|
|
818
|
+
|
|
819
|
+
const responseStep = {
|
|
820
|
+
sender: 'bot',
|
|
821
|
+
messageText: '',
|
|
822
|
+
asserters: [],
|
|
823
|
+
stepTag: 'Step 2 - check bot response',
|
|
824
|
+
not: false
|
|
825
|
+
}
|
|
826
|
+
if (useNameAsIntent) {
|
|
827
|
+
responseStep.asserters.push({
|
|
828
|
+
name: 'INTENT',
|
|
829
|
+
args: [utt.name]
|
|
830
|
+
})
|
|
831
|
+
}
|
|
832
|
+
if (incomprehensionIntents && incomprehensionIntents.length > 0) {
|
|
833
|
+
incomprehensionIntents.forEach(ii => {
|
|
834
|
+
responseStep.asserters.push({
|
|
835
|
+
name: 'INTENT',
|
|
836
|
+
args: [ii],
|
|
837
|
+
not: true
|
|
838
|
+
})
|
|
839
|
+
})
|
|
840
|
+
}
|
|
841
|
+
if (incomprehensionUtt) {
|
|
842
|
+
responseStep.messageText = incomprehensionUtt
|
|
843
|
+
responseStep.not = true
|
|
844
|
+
}
|
|
845
|
+
|
|
798
846
|
expandedConvos.push(new Convo(this._buildScriptContext(), {
|
|
799
847
|
header: {
|
|
800
848
|
name: utt.name,
|
|
@@ -811,31 +859,7 @@ module.exports = class ScriptingProvider {
|
|
|
811
859
|
messageText: utt.name,
|
|
812
860
|
stepTag: 'Step 1 - tell utterance'
|
|
813
861
|
},
|
|
814
|
-
|
|
815
|
-
? {
|
|
816
|
-
sender: 'bot',
|
|
817
|
-
asserters: [
|
|
818
|
-
{
|
|
819
|
-
name: 'INTENT',
|
|
820
|
-
args: [utt.name]
|
|
821
|
-
}
|
|
822
|
-
],
|
|
823
|
-
stepTag: 'Step 2 - check intent',
|
|
824
|
-
not: false
|
|
825
|
-
}
|
|
826
|
-
: incomprehensionUtt
|
|
827
|
-
? {
|
|
828
|
-
sender: 'bot',
|
|
829
|
-
messageText: incomprehensionUtt,
|
|
830
|
-
stepTag: 'Step 2 - check incomprehension',
|
|
831
|
-
not: true
|
|
832
|
-
}
|
|
833
|
-
: {
|
|
834
|
-
sender: 'bot',
|
|
835
|
-
messageText: '',
|
|
836
|
-
stepTag: 'Step 2 - check bot response',
|
|
837
|
-
not: false
|
|
838
|
-
}
|
|
862
|
+
responseStep
|
|
839
863
|
],
|
|
840
864
|
sourceTag: Object.assign({}, utt.sourceTag, { origUttName: utt.name })
|
|
841
865
|
}))
|
|
@@ -692,6 +692,63 @@ describe('scripting.scriptingProvider', function () {
|
|
|
692
692
|
assert.isTrue(err.message.indexOf('incomprehension utterance \'INCOMPREHENSION\' undefined') > 0)
|
|
693
693
|
}
|
|
694
694
|
})
|
|
695
|
+
it('should add incomprehension utterances to new utterance list', async function () {
|
|
696
|
+
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
697
|
+
await scriptingProvider.Build()
|
|
698
|
+
scriptingProvider.AddUtterances({
|
|
699
|
+
name: 'utt1',
|
|
700
|
+
utterances: ['TEXT1', 'TEXT2']
|
|
701
|
+
})
|
|
702
|
+
|
|
703
|
+
scriptingProvider.ExpandUtterancesToConvos({ incomprehensionUtt: 'INCOMPREHENSION', incomprehensionUtts: ['INCOMPREHENSION3', 'INCOMPREHENSION4'] })
|
|
704
|
+
assert.lengthOf(scriptingProvider.utterances.INCOMPREHENSION.utterances, 2)
|
|
705
|
+
})
|
|
706
|
+
it('should add incomprehension utterances to new default utterance list', async function () {
|
|
707
|
+
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
708
|
+
await scriptingProvider.Build()
|
|
709
|
+
scriptingProvider.AddUtterances({
|
|
710
|
+
name: 'utt1',
|
|
711
|
+
utterances: ['TEXT1', 'TEXT2']
|
|
712
|
+
})
|
|
713
|
+
|
|
714
|
+
scriptingProvider.ExpandUtterancesToConvos({ incomprehensionUtts: ['INCOMPREHENSION3', 'INCOMPREHENSION4'] })
|
|
715
|
+
assert.lengthOf(scriptingProvider.utterances.UTT_INCOMPREHENSION.utterances, 2)
|
|
716
|
+
})
|
|
717
|
+
it('should add incomprehension utterances to existing utterance list', async function () {
|
|
718
|
+
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
719
|
+
await scriptingProvider.Build()
|
|
720
|
+
scriptingProvider.AddUtterances({
|
|
721
|
+
name: 'utt1',
|
|
722
|
+
utterances: ['TEXT1', 'TEXT2']
|
|
723
|
+
})
|
|
724
|
+
scriptingProvider.AddUtterances({
|
|
725
|
+
name: 'INCOMPREHENSION',
|
|
726
|
+
utterances: ['INCOMPREHENSION1', 'INCOMPREHENSION2']
|
|
727
|
+
})
|
|
728
|
+
|
|
729
|
+
scriptingProvider.ExpandUtterancesToConvos({ incomprehensionUtt: 'INCOMPREHENSION', incomprehensionUtts: ['INCOMPREHENSION3', 'INCOMPREHENSION4'] })
|
|
730
|
+
assert.lengthOf(scriptingProvider.utterances.INCOMPREHENSION.utterances, 4)
|
|
731
|
+
})
|
|
732
|
+
it('should add incomprehension intent to asserter list', async function () {
|
|
733
|
+
const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
|
|
734
|
+
await scriptingProvider.Build()
|
|
735
|
+
scriptingProvider.AddUtterances({
|
|
736
|
+
name: 'utt1',
|
|
737
|
+
utterances: ['TEXT1', 'TEXT2']
|
|
738
|
+
})
|
|
739
|
+
|
|
740
|
+
scriptingProvider.ExpandUtterancesToConvos({ incomprehensionIntents: ['FALLBACK1', 'FALLBACK2'] })
|
|
741
|
+
assert.equal(scriptingProvider.convos.length, 1)
|
|
742
|
+
assert.equal(scriptingProvider.convos[0].conversation.length, 2)
|
|
743
|
+
assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
|
|
744
|
+
assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 2)
|
|
745
|
+
assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
|
|
746
|
+
assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'FALLBACK1')
|
|
747
|
+
assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].not, true)
|
|
748
|
+
assert.equal(scriptingProvider.convos[0].conversation[1].asserters[1].name, 'INTENT')
|
|
749
|
+
assert.equal(scriptingProvider.convos[0].conversation[1].asserters[1].args[0], 'FALLBACK2')
|
|
750
|
+
assert.equal(scriptingProvider.convos[0].conversation[1].asserters[1].not, true)
|
|
751
|
+
})
|
|
695
752
|
})
|
|
696
753
|
|
|
697
754
|
describe('assertBotResponse', function () {
|