I get a list of rows from an API call inside my lambda. I want my alexa skill intent to read a row at a time and read the next only after confirmation.
How can I achieve that?
Thanks! Anshuman
You can make use of sessionAttributes
to read row by row. When your backend receives the initial request, query the external service and respond back with the first row and keep the array of rows in sessionAttributes
. You can also set a STATE
attribute too, so that you can check this state
in AMAZON.YesIntent
or other confirmation handlers before you give the next row. This STATE
attribute will help you to validate whether the confirmation is actually for reading next row.
Ex:
"sessionAttributes": {
"row": ["This is the first row","This is the second row", .. ],
"index": 1,
"STATE": "READING_ROWS"
}
Since you want the users to confirm before reading the second row, you should append some confirmation message also with the response.
Ex: "This is the first row. Do you want to hear more?"
Use AMAZON.YesIntent and AMAZON.NoIntent
When the user say "next" check whether the state
is READING_ROWS
and based on the index
give the next item from your list. And in sessionAttributes
increment the index
.
Similarly, for AMAZON.NoIntent
provide a proper response when the users denies.
More on sessionAttributes and Response Parameters here