从意图中获取Alexa Slot值

Bil*_*l L 6 json alexa node.js alexa-skill alexa-skills-kit

我正在努力构建一个Alexa技能,并且遇到了将我的插槽值从intent对象中取出的障碍.意图对象JSON如下所示:

"intent": {
    "name": "string",
    "slots": {
      "string": {
        "name": "string",
        "value": "string"
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,第一个"字符串"值将用于识别插槽?文档包含:

A map of key-value pairs that further describes what the user meant based on a predefined intent schema. The map can be empty.

    The key is a string that describes the name of the slot. Type: string.
    The value is an object of type slot. Type: object. See Slot Object.
Run Code Online (Sandbox Code Playgroud)

这是否意味着获取插槽的关键是我在交互模型中设置的名称?我犹豫不决的唯一原因是因为我们已经在插槽中有一个名称对象,这绝对是插槽的名称 - 所以如果通过名称访问特定插槽的方式,name参数将多余(您已经知道访问插槽的名称.)

有谁知道如何访问Alexa技能中的各个槽值?

顺便说一句,我正在使用NodeJS来实现这项技能.

Tho*_*sen 18

由于我遇到了很多麻烦,一个更具体的答案(现在)是:

'PersonIntent': function () {
    var text = 'Hello ' + this.event.request.intent.slots.FirstPerson.value;

    this.emit(':tell', text);
},
Run Code Online (Sandbox Code Playgroud)

使用此意图架构:

{
    "intents": [
        {
            "intent": "PersonIntent",
            "slots": [
                {
                    "name": "FirstPerson",
                    "type": "AMAZON.DE_FIRST_NAME"
                }
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)


小智 11

这是您的结构意图的示例:

"intent": {
    "name": "MovieIntent",
    "slots": {
     "string": {
        "name": "Movie",
        "value": "Titanic"
     }
  }
}
Run Code Online (Sandbox Code Playgroud)

因此,这意味着您正在使用的Intent被命名为:Movie Intent(您在交互模型中设置的那个).你将以这种方式获得价值:

var movieSlot = intent.slots.Movie.value;
Run Code Online (Sandbox Code Playgroud)


nav*_*ule 5

截至 2019 年 7 月:您可以在您的意图处理程序中访问它,如下所示

if (handlerInput.requestEnvelope.request.intent.slots.SLOTNAME === undefined) {
    text = 'Hello! SLOTNAME not identified';
} else {
    text = 'Hello!, SLOTNAME identified: ' + handlerInput.requestEnvelope.request.intent.slots.SLOTNAME.value;
}
Run Code Online (Sandbox Code Playgroud)

替换SLOTNAME为您的插槽名称。同样非常重要的undefined是,就像作为一个对象一样,而不是undefined