Hi, is there a way in Jovo to check if an intent is triggered?
How to check if an intent is triggered?
It might not seem elegant, but a lot of people just do simple console.log
statements to trace the path when developing the app
My problem: if i have these intents and user say a phrase which trigger TypeOfSpotIntent, i I do not want to allow this if CreateSpotIntent is not triggered.
CreateSpotIntent() {
}
TypeOfSpotIntent() {
}
If I am understanding correctly, perhaps utilizing a session variable here would be good. Something like:
CreateSpotIntent() {
this.$session.$data.spotCreated = true;
// do things and stuff
}
TypeOfSpotIntent() {
if (this.$session.$data.spotCreated) {
// allowed
} else {
// not allowed
}
}
I like @natrixx solution =).
@florijan.allaraj: Depending on your use case “states” are another nice possibility https://www.jovo.tech/docs/routing/states#.
CreateSpotIntent() {
...
this.followUpState('STATE.SpotCreated')
.ask('Spot Created. What do you want to do next?'); //has to be triggered after setting state
},
STATE.SpotCreated {
TypeOfSpotIntent() {
...
}
}
The TypeOfSpot Intent can’t be reached until the CreateSpotIntent sets the state accordingly. By using states you have possibilities like creating context sensitive help or unhandled intents like bellow:
CreateSpotIntent() {
...
this.followUpState('STATE.SpotCreated')
.ask('Spot Created. What do you want to do next?'); //has to be triggered after setting state
},
STATE.SpotCreated {
TypeOfSpotIntent() {
...
},
Unhandled( ) { //unhandled in state
this.ask('Spot is set correctly but I did not understand your request. Could you repeat it?');
}
},
Unhandled( ) { //global unhandled
this.ask('Spot is not created yet. Please do so to continue');
}
I also like having my Intents seperated by states (with one file per state). You can use them via require in your app.js and later use them:
const STATE.SpotCreatedIntents = require('./states/spotCreated.js'); //at top of app.js
CreateSpotIntent() {
...
this.followUpState('STATE.SpotCreated')
.ask('Spot Created. What do you want to do next?'); //has to be triggered after setting state
},
STATE.SpotCreated: STATE.SpotCreatedIntents,