Alexa技能无法执行意图

时间:2019-08-12 07:15:28

标签: aws-lambda alexa-skill

我有技巧,我正在尝试使用alexa开发人员控制台中的“测试”功能对其进行测试。如果我给出调用名称,它将被识别为特定的意图,但是响应不匹配。 (这也许是显而易见的,我已经不再注意到了。)

我有一个LaunchRequest类型,它与调用名称一起使用。

const LaunchRequestHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
  },
  handle(handlerInput) {


    welcomeMessage = `updated welcome`;
    return handlerInput.responseBuilder
      .speak(welcomeMessage)
      .reprompt(helpMessage)
      .getResponse();
  },
};

(welcomeMessage是在外部声明的,这只是测试问题是否为其赋予了新的价值)

但是,当涉及到基于用户输入的意图(在本例中为TestIntent时,用户输入是“该技能在起作用”)时,它就不起作用了。 TestIntent的代码与LaunchRequest相同,除了意图类型和名称检查

const request = handlerInput.requestEnvelope.request;
return (request.type === "IntentRequest" &&
request.intent.name === "TestIntent");

alexa技能的json输入将输入识别为TestIntent

"request": {
    "type": "IntentRequest",
    "requestId": "amzn1.echo-api.request.601d2e89-71c1-417e-b878-790afc6f79f4",
    "timestamp": "2019-08-12T07:01:38Z",
    "locale": "en-US",
    "intent": {
        "name": "TestIntent",
        "confirmationStatus": "NONE"
    },
    "dialogState": "STARTED"
}

但是回答只是“对不起,但我不知道。您能重复一遍吗?”

1 个答案:

答案 0 :(得分:0)

您需要使用话语创建自定义意图。

示例:

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "mySkill",
            "intents": [
                {
                    "name": "TestIntent",
                    "slots": [
                        {
                            "name": "name",
                            "type": ""
                        }
                    ],
                    "samples": [
                        "test me", // This would be your utterance to identify intent
                        "testing you" // You can have multiple
                    ]
                },
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NoIntent",
                    "samples": []
                }
            ]
        }
    }
}

下面是开发者帐户的演练

1)创建意图

enter image description here

2)创建您的话语

enter image description here

然后构建您的模态。您的技能需要链接到lambda函数。

希望获得帮助!

=======更新=====

需要返回卡片回复

response = {
      outputSpeech: {
        type: "PlainText",
        text: output
      },
      card: {
        type: "Simple",
        title: title,
        content: output
      },
      shouldEndSession: shouldEndSession
    };

使用aw-sdk :(示例)

return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText)
      .withSimpleCard('Hello World', speechText)
      .getResponse();
  }