muTheTechie
muTheTechie

Reputation: 1683

How to use previous slot value in Alexa Skill?

I want to build the closed dialog model in Alexa skill. The example requirement is

Man: Alexa, what is the price of product1

Alexa: The price of product1 is 89 USD

Man: What is the size of it?

If I ask the size intent with "it" instead of product name, how alexa will understand the meaning of "it" is the product?

Upvotes: 0

Views: 481

Answers (1)

Anthony Neace
Anthony Neace

Reputation: 26003

Within the scope of a single session, you can persist the product name as a session attribute, and retrieve it again when responding to the size question.

When handling the price intent, you'll want to save off the name of your product as a session attribute. Lets call that attribute 'ProductName'. Then when handling the size intent within the same session, simply check if the ProductName attribute has been defined, and prompt for it if not.


To make this conversation more robust, define the following sample utterances in your second intent (lets call it SizeIntent) to allow a ProductName custom slot:

SizeIntent What is the size of it
SizeIntent What is the size of {ProductName} 

This defines a ProductName slot, so now you have two possible methods of input:

  • ProductName Session Attribute, via a previous part of the conversation.
  • ProductName Slot Value, via the most recent request.

To decide which value to reference:

  • If ProductName slot is not null, save it to your 'ProductName' session attribute and use it.
  • Else if ProductName attribute is not null, use it.
  • Else, prompt for ProductName.

Upvotes: 2

Related Questions