question

mm-nickname avatar image
mm-nickname asked

Handling multiple slots in single intent

Does anyone know if this is possible? I have an intent like { { "intents": [ { { "intent": "Values", "slots": [ { "name": "Value1", "type": "LITERAL" }, { "name": "Value2", "type": "LITERAL" } ] },.... in my code I have the following: var value1 = intent.slots[0]; var value2 = intent.slots[1]; however when I try to run this both values are undefined. I also tried var value1 = intent.slots.Value1; var value2 = intent.slots.Value2; But got the same result, they were both undefined. Does anyone know if this is indeed possible? and if so how would I get the values in code? Thanks for your time
alexa skills kitdebugging
10 |5000

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

jjaquinta avatar image
jjaquinta answered

Sounds like you have a Javascript problem. Your code isn't aligning with their data structure I don't do Alexa with Javascript precisely for reasons like this. I [i]think[/i] your code should be: [code] var value1 = intent.slots.Value1.value; var value2 = intent.slots.Value2.value; [/code] If you want to be certain, go to the test page on developer.amazon.com, type in a phrase, and hit test. You can then look at the outgoing structure. What I see for one of my skills includes this: [code] "intent": { "name": "MYSECRET", "slots": { "secret": { "name": "secret", "value": "I hate Javascript" } } }, [/code] So for this, it would be intent.slots.secret.value. I.e. intent.slots.[b]slotname[/b].value. Doesn't matter how many slots you have.

Note, however, that Alexa is pretty poor at multi-slot intents. It depends on your utterances and if you have static words between the slots. But, if at all possible, you are better off structuring your skill not to require multiple slots in one intent. If you can't, make sure you have business logic to deal with when Alexa only fills in one of those slots. You are going to need to reprompt the user for the other one.

10 |5000

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

mm-nickname avatar image
mm-nickname answered
Thanks very much for your help, works perfectly! Message was edited by: mm_nickname
10 |5000

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