Search code examples
alexa-skills-kitalexa-slot

How to get the number (length) of slot values for Alexa skill


I am trying to generate a random response for my Alexa Skill. I have set it up as:

  • Intent = myIntent
  • Slot = mySlot
  • Slot Type = mySlotType
  • Slot Values = {A,B,C,D} //the ids are unique numbers 1 - 4

when the user says a word such as A it uses this to create a response. Now I want to add a case for 'random'.

So Slot Values = {random,A,B,C,D}. //ID for random is 0

When the user says random, I want to randomly choose from the other Slot Values and use this to create a response.

Can Slot Value ID be used to return the Slot Value value?

Anybody know a good way to do this? I am a novice so excuse any obvious oversights.


Solution

  • This might be a workaround for your problem. You can get the JSON structure of your interaction model and use it as a constant in your lambda index.js file. I usually use this official tool for generating backend code for my skill : https://s3.amazonaws.com/webappvui/skillcode/v2/index.html.

    When you'll generate the code through this tool, you'll see that the code generated also has the whole interaction model used as constant. Since you will have the whole JSON schema of the interaction model at your disposal, you can perform any action on it.

    Note: If you don't know where to get JSON schema of your interaction model, scroll down on the build tab of your skill on the developer console, you'll find a menu of JSON editor on the left navigation. It will give you the JSON schema of your interaction model.