简体   繁体   中英

Using sessionAttributes in Alexa Skill

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

  • In this intent my skill will look into a database and list out the to-do items stored in the database. After listing the items, Alexa will go on to say "do you want me to list detailed info on these to-do items?", to handle this I will pass the items retrieved in the previous session as sessionAttributes . When asked to list detailed info on the items, I will extract the previously forwarded sessionAtrributes and compose a detailed speech response.
  • So for this intent I have to sample utterances
    • list my to-do items
    • yes

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

  • list my completed items
  • yes

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; ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM