I am building an Alexa skill and not quite sure if I am using sessionAtrributes
correctly. I know sessionAttributes
are used to carry-forward a session's data to next invocation.
So I have these two intents
1) ListToDoItem
sessionAttributes
. When asked to list detailed
info on the items, I will extract the previously forwarded
sessionAtrributes
and compose a detailed speech response.The utterance 'yes' will be used so that the sessionAttributes
can be extracted to create a detailed speech response.
2) ListDoneItems
This intent will be used to list out completed items. It is similar to the previous intent, the only difference being, this intent will list out completed items.
For this intent will have 2 sample utterances
Like before it has an 'yes' to generate a detailed speech response based on the sessionAttributes.
But the problem I have is that when I reply 'yes' to the ListDoneItems
intent's 'Do you want me to list the completed items'?, the next intent request generated is of type ListToDoItems
instead of ListDoneItems
, even though I have set shouldEndSession
to false
in my skill response. This is happening because there is a crossover between sample utterances between my intents. So is having similar intents in different intents wrong? How to design interaction model to create a multi-turn dialog in order to use in sessionAttributes
?
I think this will be of use to someone searching for answer.
Basically in the sample utterance you should not include phrases for your re-prompts; i.e. in my case I should not add 'yes' as an utterance. Instead I should be using Amazon.YesIntent
.
When using Amazon.YesIntent
, you should maintain a state machine in your SessionAttributes
pointing to the last invoked intent. For example if two or more of your intents have a possible case where the user response could invoke a YesIntent
, you should store the last invoked intent name and the associated session data in the SessionAttributes
. So in the function which handles the YesIntent
, you should check the state of your previous invocations and delegate to control to the corresponding intent handler.
In my case I will store previously invoked intent name as key and its associated data as it's value in the session.attributes
;
"session": {
"new":"false",
"sessionId": "sessionId",
"application": {
"applicationId": "applicationId"
},
"attributes": {
"PreviousIntent": {
"PreviousIntentData"
}
}
In the function which handles YesIntent
, check the for the previous state (session.attributes.PreviousIntent
) and delegate the control to the function which handles that intent.