无法在 Alexa 技能中执行意图
Unable to execute intents in Alexa Skills
出于某种原因,我无法在我的 Alexa 技能中执行我的一些意图。这是讨论的原样。
- 'open my passwords'
Alexa:你的密码是什么?
- 'my passphrase is test'
Alexa:你来了。
- 'what is my wifi password?'
Alexa:请求的技能响应有问题。
这是对话的截图。
这是我可以接受的话语,其中 type
是插槽类型 AMAZON.SearchQuery
。
此时我正试图联系 GetPasswordHandler
让她说 'hello world'。但我无法记录或达到这个意图。我曾一度达到它并能够执行此意图,但由于某种原因它现在无法正常工作,我只收到通用的 There was a problem with the requested skill's response
错误。
我尝试绕过这些意图,因为我认为它们列出的顺序可能是问题所在,但我还没有找到可行的顺序。我还尝试使用 CloudWatch 记录可能出现的任何问题,但我对它还很陌生,而且我可能使用不当,因为我觉得除了警报之外,这些信息并不是很有帮助。我从测试面板的 JSON Input 中只能发现响应无效。这是 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": []
}
}
}
我最后只是重写了意图,它们现在可以工作了。我不确定到底出了什么问题,但我注意到当我添加新意图时,它们被添加到我的技能清单的底部,而不是以前的顺序。我不是 100% 确定这是问题所在,但这是我在重新制定意图时注意到的唯一变化。
出于某种原因,我无法在我的 Alexa 技能中执行我的一些意图。这是讨论的原样。
- 'open my passwords'
Alexa:你的密码是什么?
- 'my passphrase is test'
Alexa:你来了。
- 'what is my wifi password?'
Alexa:请求的技能响应有问题。
这是对话的截图。
这是我可以接受的话语,其中 type
是插槽类型 AMAZON.SearchQuery
。
此时我正试图联系 GetPasswordHandler
让她说 'hello world'。但我无法记录或达到这个意图。我曾一度达到它并能够执行此意图,但由于某种原因它现在无法正常工作,我只收到通用的 There was a problem with the requested skill's response
错误。
我尝试绕过这些意图,因为我认为它们列出的顺序可能是问题所在,但我还没有找到可行的顺序。我还尝试使用 CloudWatch 记录可能出现的任何问题,但我对它还很陌生,而且我可能使用不当,因为我觉得除了警报之外,这些信息并不是很有帮助。我从测试面板的 JSON Input 中只能发现响应无效。这是 SessionEndRequest
.
"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": []
}
}
}
我最后只是重写了意图,它们现在可以工作了。我不确定到底出了什么问题,但我注意到当我添加新意图时,它们被添加到我的技能清单的底部,而不是以前的顺序。我不是 100% 确定这是问题所在,但这是我在重新制定意图时注意到的唯一变化。