0

I have an intent set up with a list of the planets in the solar system.

 {
      "intent": "PlanetIntent",
      "slots": [
        {
          "name": "Planet",
          "type": "LIST_OF_PLANETS"
        }
      ]
    },

I'm trying to set it up so that when a user names a planet my code simply returns the name of that planet back to them. If they say a planet not in the list then it'll return with an error (or go to unhandled which is what I initially assumed would happen).

But no matter what I try, from the most basic to the most complex code, my code will always return any word that is said, rather than just the relevant slot value.

So neither

'PlanetIntent': function () {
 var selection = this.event.request.intent.slots.Planet.value;

        this.response.speak(selection);
        this.emit(':responseReady');
}

nor this

'PlanetIntent': function () {
 var selection = '';

        if ( !this.event.request.intent.slots.Planet || 
        this.event.request.intent.slots.Planet.value == '') {
            this.emitWithState('AMAZON.HelpIntent'); 

        } else {
            selection = this.event.request.intent.slots.Planet.value;

        this.response.speak(selection);
        this.emit(':responseReady');
  }
},

Seem to stop random values from getting through. If you say Mars, it returns Mars, if you say turnip, it returns turnip. Any ideas. I just want to limit it to return only responses from my list of planets!

dpr47
  • 11
  • 1

1 Answers1

1

The list you provide for slots are just Hints, not a filter or restriction. You will definitely need to filter the list in your code.

Since you're only looking for the names of planets in our solar system, this shouldn't be too difficult: 7-9 values depending whether you want to count Pluto and/or include Earth also, a bit tougher if you start including their moons, and quite challenging if you include known planets of other stars :-)

Ron Lisle
  • 1,164
  • 6
  • 11