0
votes

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"
    }
  }
}
1
@mplungjan It seems most of those posts have to do with people trying to access the slot values at the wrong place in the event object. I'm using the same logic to get the slot value across multiple intent handlers without a problem, and the value isn't appearing in the Input JSON panel of the alexa dev console test page.SimpleJ

1 Answers

1
votes

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.