无法执行Alexa技能中的意图

问题描述 投票:0回答:1

出于某种原因,我无法执行我的Alexa技能中的一些意图。这是讨论的原样。

  1. '打开我的密码'

Alexa:您的密码是什么?

  1. '我的密码短语是测试'

[Alexa:您在。

  1. '我的WiFi密码是什么?'

Alexa:所请求的技能响应有问题。

这里是对话的屏幕截图。

enter image description here

这是我可以接受的发音,其中type是插槽类型AMAZON.SearchQuery

enter image description here

[目前,我只是想到达GetPasswordHandler并让她说“你好,世界”。但是我无法登录或达到此目的。我已经到达某一点,并且能够执行此意图,但是由于某种原因,它现在不起作用,并且我只收到通用的There was a problem with the requested skill's response错误。

我曾尝试绕过这些意图,因为我认为也许列出它们的顺序是问题所在,但我还没有找到一个可行的顺序。我还尝试使用CloudWatch记录可能出现的任何问题,但是我对此很陌生,并且可能使用不正确,因为除了警报这一事实之外,我觉得该信息不是很有用。从测试面板中的JSON输入中,我所能确定的是响应无效。这是SessionEndRequest的输入JSON中的错误。

"error": {
            "type": "INVALID_RESPONSE",
            "message": "An exception occurred while dispatching the request to the skill."
        }

这是初始GetPassword请求的输入JSON。

"request": {
        "type": "IntentRequest",
        "requestId": "amzn1.echo-api.request.bdae78eb-3c92-49a8-b3af-c590e284b842",
        "timestamp": "2020-02-05T17:23:03Z",
        "locale": "en-US",
        "intent": {
            "name": "GetPassword",
            "confirmationStatus": "NONE",
            "slots": {
                "type": {
                    "name": "type",
                    "value": "WiFi",
                    "confirmationStatus": "NONE",
                    "source": "USER"
                }
            }
        }
    }

这是我的Lambda代码。

// This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK (v2).
// Please visit https://alexa.design/cookbook for additional examples on implementing slots, dialog management,
// session persistence, api calls, and more.
const Alexa = require('ask-sdk-core');

const passphrase = 'test';

const instructions = `You can access existing passwords or create a new password. 
            Just specify password type, such as wifi, laptop or cellphone.`;

// the intent being invoked or included it in the skill builder below.


 const LoginHandler = {
     canHandle(handlerInput) {
         return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
             && handlerInput.requestEnvelope.request.intent.name === "Login";
     },
     handle(handlerInput) {
         console.log('test');
         const request  = handlerInput.requestEnvelope.request;
         const responseBuilder = handlerInput.responseBuilder;
          let slotValues = handlerInput.requestEnvelope.request.intent.slots

         if (slotValues && slotValues.passphrase.value === passphrase){
             var attributes = handlerInput.attributesManager.getSessionAttributes()
             attributes.isLoggedIn = true
             const speakOutput = "You're in.";
             return handlerInput.responseBuilder
             .speak(speakOutput)
             .reprompt(speakOutput)
             .getResponse();  

         } else {
             const speakOutput = `Passphrase not recognized. What is your passphrase?`;

             return handlerInput.responseBuilder
             .speak(speakOutput)
             .reprompt(speakOutput)
             .getResponse();  
         }
     }
 };

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
    },
    handle(handlerInput) {
        var attributes = handlerInput.attributesManager.getSessionAttributes();
        if (attributes.isLoggedIn){
            const speakOutput = `Welcome to your passwords. ${instructions}`;
            return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse(); 
        } else {
            const speakOutput = `What is your pass phrase?`;
            return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();     
        }

    }
};


// THIS IS THE INTENT THAT DOES NOT WORK
const GetPasswordHandler = {
    canHandle(handlerInput) {
        return (Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === "GetPassword");
    },
    handle(handlerInput) {
        console.log('yes');

        const speakOutput = 'hello world';
            return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();  
    }
};


const HelpIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
    },
    handle(handlerInput) {
        const speakOutput = 'You can say hello to me! How can I help?';

        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};

const CancelAndStopIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.CancelIntent'
                || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.StopIntent');
    },
    handle(handlerInput) {
        const speakOutput = 'Goodbye!';
        handlerInput.sessionAttributes.isLoggedIn = false 
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .getResponse();
    }
};

const SessionEndedRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest';
    },
    handle(handlerInput) {
        // Any cleanup logic goes here.
        handlerInput.sessionAttributes.isLoggedIn = false 
        return handlerInput.responseBuilder.getResponse();
    }
};

// The intent reflector is used for interaction model testing and debugging.
// It will simply repeat the intent the user said. You can create custom handlers
// for your intents by defining them above, then also adding them to the request
// handler chain below.
const IntentReflectorHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest';
    },
    handle(handlerInput) {
        const intentName = Alexa.getIntentName(handlerInput.requestEnvelope);
        const speakOutput = `You just triggered ${intentName}`;

        return handlerInput.responseBuilder
            .speak(speakOutput)
            //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
            .getResponse();
    }
};

// Generic error handling to capture any syntax or routing errors. If you receive an error
// stating the request handler chain is not found, you have not implemented a handler for
// the intent being invoked or included it in the skill builder below.
const ErrorHandler = {
    canHandle() {
        return true;
    },
    handle(handlerInput, error) {
        handlerInput.sessionAttributes.isLoggedIn = false 
        console.log(`~~~~ Error handled: ${error.stack}`);
        const speakOutput = `Sorry, I had trouble doing what you asked. Please try again. ${error.stack}`;

        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};


// The SkillBuilder 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,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler,
        LoginHandler,
        GetPasswordHandler,
        HelpIntentHandler,
        IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
    )
    .addErrorHandlers(
        ErrorHandler,
    )
    .lambda();

这是我的JSON。

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "my passwords",
            "intents": [
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NavigateHomeIntent",
                    "samples": []
                },
                {
                    "name": "GetPassword",
                    "slots": [
                        {
                            "name": "type",
                            "type": "AMAZON.SearchQuery"
                        }
                    ],
                    "samples": [
                        "password for my {type}",
                        "{type} password",
                        "what is my {type} password"
                    ]
                },
                {
                    "name": "AMAZON.MoreIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NavigateSettingsIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NextIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.PauseIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.ResumeIntent",
                    "samples": []
                },
                {
                    "name": "Login",
                    "slots": [
                        {
                            "name": "passphrase",
                            "type": "AMAZON.SearchQuery"
                        }
                    ],
                    "samples": [
                        "my passphrase is {passphrase}"
                    ]
                },
                {
                    "name": "AMAZON.PageUpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.PageDownIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.PreviousIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.ScrollRightIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.ScrollDownIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.ScrollLeftIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.ScrollUpIntent",
                    "samples": []
                }
            ],
            "types": []
        }
    }
}

出于某种原因,我无法执行我的Alexa技能中的一些意图。这是讨论的原样。 “打开我的密码” Alexa:您的密码是什么? “我的密码是测试” ...

amazon alexa alexa-skills-kit alexa-skill
1个回答
0
投票

我最终只是重写了意图,它们现在可以工作了。我不确定到底出了什么问题,但是我注意到当我添加新的意图时,它们被添加到了我的技能清单的底部,而不是之前的顺序。我不是100%确信这是问题所在,但这是我重新制定意图时唯一注意到的更改。

© www.soinside.com 2019 - 2024. All rights reserved.