Alexa (Amazon Echo) conversation skill – Using Session Attributes (JavaScript – AWS Lambda)

Question:

this might be an easy one but I couldn’t figure it out in days.

I want to make Alexa have a conversation, like;

>> Alexa, start testSkill.

A: Test Skill started. Tell me a number.

>> One.

A: Okay, tell me a color now.

>> Blue.

A: And finally, tell me an animal name.

>> Chicken.

A: You told me one, blue and chicken.

I found out that I have to handle the Session Attributes of the skill, which is a JSON holds and transfers the information between intents.

I use functions like this ;

A piece of code from onIntent() function where I call the above functions. (I know it’s wrong but couldn’t figure out the right way)

And the Intent Schema JSON is like that;

]
}

So, am I doing all of the things wrong ? Where is the mistake ? And, how can I build a conversation like I mentioned ? Thanks from now.

Answer:

Since no one gave you any answer yet I thought I’d give you my two cents. My language of choice is Python but I can give you some high-level ideas.

  • Use a session object to keep track of everything related to the conversation. After you compute the “response”, serialize your session object into the session json and deserialize it in the next intent request.
  • Maintain a conversation state and use a finite-state-machine approach to know where you are and what callback to execute given an intent and a specific conversation state.
  • Decouple your conversation logic from the ASK interface as much as you can. Try to write tests you can run locally.

If you want to see how I implemented these, check out:

Leave a Reply