Search code examples
javaalexa-skills-kitalexa-voice-service

Enumerate Custom Slot Values from Speechlet


Is there any way to inspect or enumerate the Custom Slot Values that are set-up in your interaction model? For Instance, Say you have an intent schema with the following intent:

{
  "intent": "MySuperCoolIntent",
  "slots":
  [
    {
      "name": "ShapesNSuch",
      "type": "LIST_OF_SHAPES"
    }
  ]
}    

Furthermore, you've defined the LIST_OF_SHAPES Custom Slot to have the following Values:

SQUARE
TRIANGLE
CIRCLE
ICOSADECAHECKASPECKAHEDRON
ROUND
HUSKY

Question: is there a method I can call from my Speechlet or my RequestStreamHandler that will give me an enumeration of those Custom Slot Values??

I have looked through the Alexa Skills Kit's SDK Javadocs Located Here

And I'm not finding anything.

I know I can get the Slot's value that is sent in with the intent:

String slotValue = incomingIntentRequest.getIntent().getSlot("LIST_OF_SHAPES").getValue();  

I can even enumerate ALL the incoming Slots (and with it their values):

Map<String, Slot> slotMap = IncomingIntentRequest.getIntent().getSlots();
for(Map.Entry<String, Slot> entry : slotMap.entrySet())
{
    String key = entry.getKey();
    Slot slot = (Slot)entry.getValue();
    String slotName = slot.getName();
    String slotValue = slot.getValue();
    //do something nifty with the current slot info....
}

What I would really like is something like:

String myAppId = "amzn1.echo-sdk-ams.app.<TheRestOfMyID>"; 

List<String> posibleSlotValues = SomeMagicAlexaAPI.getAllSlotValues(myAppId, "LIST_OF_SHAPES");

With this information I wouldn't have to maintain two separate "Lists" or "Enumerations"; One within the interaction Model and another one within my Request Handler. Seems like this should be a thing right?


Solution

  • No, the API does not allow you to do this.

    However, since your interaction model is intimately tied with your development, I would suggest you check in the model with your source code in your source control system. If you are going to do that, you might as well put it with your source. Depending on your language, that also means you can probably read it during run-time.

    Using this technique, you can gain access to your interaction model at run-time. Instead of doing it automatically through an API, you do it by best practice.

    You can see several examples of this in action for Java in TsaTsaTzu's examples.