首页 文章

Alexa完全匹配样本话语无法通过槽值

提问于
浏览
0

我有一个名为“rollDice”的意图的Alexa技能 . 意图有两个话语:

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

sides 在下面定义了插槽类型 AMAZON.NUMBER .

技能构建成功,我打开它并运行"roll a 20 sided dice",它运行正确的意图请求处理程序,但是当我尝试使用 sides 插槽的值时,它是 undefined . 我检查了JSON输入面板,我发现它没有被传递:

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

这是我处理 rollDice 意图的代码:

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')}`;
};

我从Alexa得到的回应:

Rolled a 6 sided dice and got 4. undefined

我在其他几个意图处理程序中使用 slot 函数没有问题,所以我不知道这个问题,但这里只是以下情况:

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

编辑:

在使用 roll a 20 sided dice 运行后,这是我的Lambda函数中 event.request.intent 的值:

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

1 回答

  • 1

    当您使用alexa进行测试时,您必须考虑您正在测试VOICE服务并且您正在模拟SPEECH而不是文本 . 你不能说“身体上掷20个骰子” . 因此,如果你的意思是滚动一个20面骰子,你必须说“滚动一个二十面骰子”因为这就是你怎么说数字20 .

相关问题