I want to build a custom Alexa skill with the following behavior:
When I invoke the skill (without a intent utterance) the session should stay open all the time until the user closes the skill manually
When I invoke the skill using a intent utterance (e.g. "ask Skillname, how much does a day ticket cost") the session should close immediately after the response.
Why does this behavior make sense: I am building a skill that acts as a FAQ and in the case that a user simply wants to know one specific thing, they can just invoke it using the utterance and call it a day. Otherwise they open the skill and ask multiple questions in context of the skill.
I'm using the nodejs package ask-sdk
to build my skill.
What actions would be necessary to accomplish said behavior?
Can this behavior interfere with other request types like the AudioPlayer? How would I only apply this behavior on SSML/Text-only intents?
I tried to use .withShouldEndSession(false)
on the LaunchRequest but this doesn't apply to all subsequent Intents.
With every response you have to specify again, that the session should not end.
So the problem on the other Intent handlers is, when to end and when not to end.
One option is, to set a session variable in the Launch request. On any other Intent handler you can check if the session variable is set. If so do not close the session otherwise do.
Keep in mind, that on every Intent Handler you need to copy over the request session variable(s) into the response (or they get lost).
Furthermore you should provide an additional intent to close the session.
If you plan a public skill, keep in mind, that during the certification process it is required, that any Intend which does not close the session have a question at the end of its prompt. So you would need to add one if the session variable is set.