question

Abdelilah Lbardi avatar image
Abdelilah Lbardi asked

How to identify the asked question in the skill backend?

Hello,

I am working on a simple "True or False" with a custom skill development.

Giving an example with the following scenario, I can not identify the question that I ask to the user to define if it's true or not.

U: Alexa, start "true or false facts"

A: Hello there.

U: Give me a random question

A: Jodie Foster won her first Oscar for her role in the movie TaxiDriver?

U: this is not true.

A: Bravo! Good answer. Jodie Foster was nominated for her role in Taxi Driver,but she did not win the statuette. Want an other question?

A: yes

......

I can not define how to keep the dialog continuity and the giving answer is related to what question.

Thanks a million.

intentshow-toask cliinteraction model
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

TheStrandedStarfish avatar image
TheStrandedStarfish answered

Easiest way is to use session attributes. You store this at the upper level of the response in a field named sessionAttributes.

{
        'version': '1.0',
        'sessionAttributes': sessionAttributes,
        'response': speechletResponse
    }

You can then retrieve them in the next JSON Request sent to you in a field called attributes in the session

{
  "version": "string",
  "sessionAttributes": {
    "key": "value"
  }
...
}
2 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Abdelilah Lbardi avatar image Abdelilah Lbardi commented ·

Thanks a million for your answer. I just found about it in the documentation.

A.

1 Like 1 ·
TheStrandedStarfish avatar image TheStrandedStarfish Abdelilah Lbardi commented ·

BTW, apparently if you use NodeJS, there is a simple way to do this:

this.attributes.<key> = <value> 

Info here: https://developer.amazon.com/blogs/alexa/post/2279543b-ed7b-48b4-a3aa-d273f7aab609/alexa-skill-recipe-using-session-attributes-to-enable-repeat-responses

0 Likes 0 ·