首页 > 解决方案 > Alexa Skills - 如何从另一个意图返回具有槽值的意图?

问题描述

如何从另一个意图返回具有槽值的意图?

我想通过在另一个意图中返回它的槽值来触发一个意图。

这是我的 JSON 文件的示例:

{
  "interactionModel": {
    "languageModel": {
      "invocationName": "movie antakshari",
      "intents": [
        {
          "name": "SchoolIntent",
          "slots": [
            {
              "name": "Subject",
              "type": "subjects"
            }
          ],
          "samples": ["{subjects}"]
        },
        {
          "name": "teachersIntent",
          "slots": [],
          "samples": ["teachers"]
        },
      ],
      "types": [
        {
          "name": "subjects",
          "values": [
            {
              "name": {"value": "maths"}
            },
            {
              "name": {"value": "english"}
            }
          ]
        }
      ]
    }
  }
}

这是我的 index.js 文件:

const teacherIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'teacherIntent';
    },

    handle(handlerInput) {
        if (some condition) {
            // Here I want to return the schoolIntentHandler with a slot value maths
        }
    }
}

标签: alexaalexa-skills-kit

解决方案


意图调用由用户话语驱动。用户必须说些什么,这样 Alexa 服务才能将用户所说的内容与模型中的意图相匹配。

在您的情况下,您需要通过正确引导用户来让用户调用 schoolIntent。即你需要从这里返回一个演讲,让用户说出符合 schoolIntent 的内容

handle(handlerInput) {
    if (some condition) {
        // Here I want to return the schoolIntentHandler with a slot value maths
        //
        // You need to return a speech from here that will make user to utter something that matches schoolIntent.
    }
}

推荐阅读