Search code examples
javascriptalexa-skills-kitalexa-slot

Alexa exactly matching sample utterance fails to pass slot value through


I have an Alexa skill with an intent named "rollDice". The intent has two utterances:

roll a {sides} sided dice
roll a {sides} sided die

sides is defined below with the slot type AMAZON.NUMBER.

The skill builds successfully, and I open it and run "roll a 20 sided dice", and it runs the correct intent request handler, but when I try to use the value of the sides slot, it's undefined. I checked the JSON Input panel, and I see it's not being passed:

"intent": {
    "name": "rollDice",
    "confirmationStatus": "NONE",
    "slots": {
        "sides": {
            "name": "sides",
            "confirmationStatus": "NONE"
        }
    }
}

Here is my code that handles the rollDice intent:

module.exports = ({ store, slot }) => {
  const sideCount = +slot('sides', 6);
  const roll = 1 + Math.floor(Math.random() * sideCount);
  store.state.rolls.push({sideCount, roll});
  return `Rolled a ${sideCount} sided dice and got ${roll}. ${slot('sides')}`;
};

And the response I get from Alexa:

Rolled a 6 sided dice and got 4. undefined

I'm using the slot function in several other intent handlers without a problem, so I don't think it's the issue, but here it is just in case:

slot(name, defaultValue) {
  const { intent } = this;
  const slot = intent && intent.slots && intent.slots[name];
  return slot && slot.value || defaultValue;
}

EDIT:

This is the value of event.request.intent in my Lambda function after being run with roll a 20 sided dice:

{
  "name": "rollDice",
  "confirmationStatus": "NONE",
  "slots": {
    "sides": {
      "name": "sides",
      "confirmationStatus": "NONE"
    }
  }
}

Solution

  • When you test with alexa, you have to consider that you are testing a VOICE service and you are simulating a SPEECH instead of a text. You cannot say "roll a 20 sided dice" physically. So if you mean roll a 20 sided dice, you have to say "roll a twenty sided dice" cause thats how you say the number 20.