Alexa的两个意图;第二意图未触发

时间:2019-03-22 10:51:49

标签: node.js aws-lambda alexa

我无法在Alexa的hello world demo中工作的两个意图。我在AboutSarawakIntent中添加了触发另一个lambda函数的方法。

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "greet chief minister",
            "intents": [
                ...,
                {
                    "name": "HelloWorldIntent",
                    "slots": [],
                    "samples": [
                        "Ok",
                        "Awesome",
                        "Good",
                        "Great",
                        "Okay",
                        "Yes",
                        "Good Afternoon",
                        "Good Morning",
                        "Hello",
                        "Say Hello",
                        "Say hi",
                        "Tell Me More"
                    ]
                },
                {
                    "name": "AboutSarawakIntent",
                    "slots": [],
                    "samples": [
                        "how do you do",
                        "I am fine",
                        "how are you"
                    ]
                },
                ...
            ],
            "types": []
        }
    }
}

因此以下代码来自lambda函数,其中我添加了AboutSarawakIntentHandler来侦听AboutSarawakIntent。

....
const HelloWorldIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest'
            && handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
    },
    handle(handlerInput) {
        const randomNumber = Math.floor(Math.random() * speeches.length);
        const speechText = speeches[randomNumber];
        const continueSpeech = continues[randomNumber];
        return handlerInput.responseBuilder
            .speak(speechText)
            .reprompt(continueSpeech)
            .getResponse();
    }
};
const AboutSarawakIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest'
            && handlerInput.requestEnvelope.request.intent.name === 'AboutSarawakIntent';
    },
    handle(handlerInput) {
        const speechText = 'Welcome to Sarawak'
        const continueText = 'I am honored to be here.';
        return handlerInput.responseBuilder
            .speak(speechText)
            .reprompt(continueText)
            .WithStandardCard('Greeting from Sarawak', 'Welcome Everybody', 'https://s1.bukalapak.com/img/6425275433/w-1000/banner_selamat_datang_di_pernikahan.jpg', 'https://s1.bukalapak.com/img/6425275433/w-1000/banner_selamat_datang_di_pernikahan.jpg')
            .getResponse();
    }
};
....

// This handler acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        HelloWorldIntentHandler,
        AboutSarawakIntentHandler,
        HelpIntentHandler,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler,
        IntentReflectorHandler) // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
    .addErrorHandlers(
        ErrorHandler)
    .lambda();

每次使用发声时,我都可以成功触发HelloWorldIntent,但是另一个总是回馈给我'对不起,我听不懂您在说什么。请再试一遍。'有人可以告诉我哪里可能出问题吗?

1 个答案:

答案 0 :(得分:0)

我最终可以触发,因为我的alexa设备不支持图片输出。所以WithStandardCard总是给我错误。所以我将其更改为WithSimpleCard,并且可以正常工作。

https://ask-sdk-for-nodejs.readthedocs.io/en/latest/Building-Response.html