How to pass list of value to an alexa slot in an intent

604 Views Asked by At

I want to define an order intent something like "I want two pencil,one notebook, four cardbox".

In alexa build model it looks something like the following I want {itemQuantity}{itemList}

here {itemQuantity} is defined as Amazon.number and {itemList} is defined as custom slot which could have this set of values {pencil,notebook,eraser,cardbox,sharpner}.

Now If I make the following utterance "I want three eraser" ,it worked perfectly.it returns itemQuantity as 3 and itemList as eraser.

But when I make the intent with multiple values like this "I want two pencil one notebook four cardbox". It returns me itemQuantity as 2 and itemValue as "two pencil one notebook four cardbox".

Rest of the string come entirely as itemList.

I want to get this input in form of array/list like itemQuantity = {2,1,4} itemList = {pencil,notebook,cardbox}

1

There are 1 best solutions below

0
On

You can't do that in an easy way.

The simplest thing you can do is define utterances like:

I want {itemQuantity1}{item1}{itemQuantity2}{item2}...

So you have to specify in the utterance all the possibilities for the list. If you have maximum fixed length list I think it is the right way to do.

Or you can use AMAZON.SearchQueryslot (link) and process the whole phrase (that should be two pencil one notebook four cardbox) in the backend of the skill and extract the values that you need.

But in that way you have the limitation of the needed carrier phrase for that type of slot (see linked docs).

Another workaround could be catch all slots (not working 100% of the time btw) but as above you have to deal with the whole phrase in the backend and process it.