I have found that in almost all the Alexa skills that I’ve made using the Jovo framework, I have had to add logic to determine if the skill was entered without an intent (directly into the LAUNCH handler) or with an intent (coming in through ON_REQUEST). Depending on how the skill was entered, I either use this.ask calls (when LAUNCHed) or this.tell calls (called with intent). Essentially, when the user invokes the skill by opening it only with the Invocation phrase I want the session to remain open. Otherwise, I want the skill to respond to the intent and then exit.
My question is, what is the best way to do this? What I have done is to add a session variable called endAfterIntent. If the LAUNCH intent is called, I set this.$session.$data.endAfterIntent to false. In the ON_REQUEST handler, I have the following check:
if (typeof this.$session.$data.endAfterIntent === 'undefined') {
this.$session.$data.endAfterIntent = true;
}
Then I have logic around all the speechBuilder calls:
if (this.$speech.$data.endAfterIntent) {
this.tell(this.$speech);
} else {
this.ask(this.$speech, this.$reprompt);
}
This seems a bit clunky to me and I was wondering if there was a better way of determining how the skill was invoked rather than having to maintain my own session variable. Is there a method call that I can make to find out if the skill was entered with or without an intent?
I appreciate any tips or suggestions of better ways to do this.