Javascript 第一项技能,就是错误处理程序

Javascript 第一项技能,就是错误处理程序,javascript,json,alexa,alexa-skills-kit,alexa-skill,Javascript,Json,Alexa,Alexa Skills Kit,Alexa Skill,我想编写我的第一个Alexa技能代码,但我的第一个意图是无法正常工作。错误处理程序进入并以“对不起,…”回应 我想做一个省道计算器,第一个目的应该是: "Ok ${spieleranzahl} Spieler, wie viele Punkte sollen gespielt werden?" 英文: "Ok ${numerOfPlayers} players, how many points are we going to play?" 这是我的js代码,有人能告诉我我做错了什么吗?(请不

我想编写我的第一个Alexa技能代码,但我的第一个意图是无法正常工作。错误处理程序进入并以“对不起,…”回应

我想做一个省道计算器,第一个目的应该是:

"Ok ${spieleranzahl} Spieler, wie viele Punkte sollen gespielt werden?"
英文:

"Ok ${numerOfPlayers} players, how many points are we going to play?"
这是我的js代码,有人能告诉我我做错了什么吗?(请不要介意JSON下面的间距问题)

//此示例演示如何使用Alexa技能工具包SDK(v2)处理Alexa技能的意图。
//请访问https://alexa.design/cookbook 有关实现插槽、对话框管理、,
//会话持久性、api调用等。
const-Alexa=require('ask-sdk-core');
常量LaunchRequestHandler={
canHandle(handlerInput){
返回Alexa.getRequestType(handlerInput.requestEnvelope)='LaunchRequest';
},
句柄(handlerInput){
const speakOutput=‘好吧,我知道你是谁?’;
const repromtText=“我们的生活充满活力。”;
返回handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(repromtext)
.getResponse();
}
};
//ErfasseSpieleranzahlHandler
常数ErfasseSpieleranzahlHandler={
canHandle(handlerInput){
返回Alexa.getRequestType(handlerInput.requestEnvelope)==“IntentRequest”
&&Alexa.getIntentName(handlerInput.requestEnvelope)=='ErfasseSpieleranzahl';
},
句柄(handlerInput){
const spieleranzahl=handlerInput.requestEnvelope.request.intent.slots.spieleranzahl.value;
const speakOutput=`Ok${spieleranzahl}Spieler,wie viele Punkte sollen gespielt werden?`;
返回handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt(repromtext)
.getResponse();
}
};
常量HelpIntentHandler={
canHandle(handlerInput){
返回Alexa.getRequestType(handlerInput.requestEnvelope)==“IntentRequest”
&&Alexa.getIntentName(handlerInput.requestEnvelope)==“AMAZON.HelpIntent”;
},
句柄(handlerInput){
const speakOutput='你可以向我打招呼!我能帮什么忙?';
返回handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
常量CancelAndStopIntentHandler={
canHandle(handlerInput){
返回Alexa.getRequestType(handlerInput.requestEnvelope)==“IntentRequest”
&&(Alexa.getIntentName(handlerInput.requestEnvelope)==“AMAZON.CancelIntent”
||Alexa.getIntentName(handlerInput.requestEnvelope)='AMAZON.StopIntent');
},
句柄(handlerInput){
const speakOutput='再见!';
返回handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();
}
};
常量SessionEndRequestHandler={
canHandle(handlerInput){
返回Alexa.getRequestType(handlerInput.requestEnvelope)='SessionEndRequest';
},
句柄(handlerInput){
//任何清理逻辑都在这里。
返回handlerInput.responseBuilder.getResponse();
}
};
//意图反射器用于交互模型测试和调试。
//它将简单地重复用户所说的意图。您可以创建自定义处理程序
//通过在上面定义它们,然后将它们添加到请求中,来实现您的意图
//下面是处理链。
常量IntentReflectorHandler={
canHandle(handlerInput){
返回Alexa.getRequestType(handlerInput.requestEnvelope)='IntentRequest';
},
句柄(handlerInput){
const intentName=Alexa.getIntentName(handlerInput.requestEnvelope);
const speakOutput=`您刚刚触发了${intentName}`;
返回handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt('如果要保持会话打开以供用户响应,请添加reprompt')
.getResponse();
}
};
//用于捕获任何语法或路由错误的通用错误处理。如果你收到一个错误
//如果声明找不到请求处理程序链,则您尚未实现的处理程序
//正在调用或包含在下面的技能生成器中的意图。
常量错误处理程序={
canHandle(){
返回true;
},
句柄(handlerInput,错误){
log(`Error handled:${Error.stack}`);
const speakOutput=`对不起,我在执行您的请求时遇到问题。请再试一次。`;
返回handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
//SkillBuilder充当技能的入口点,路由所有请求和响应
//向上面的处理程序加载有效负载。确保您已经安装了任何新的处理程序或拦截器
//定义如下。顺序很重要——它们是自上而下处理的。
exports.handler=Alexa.SkillBuilders.custom()
.addRequestHandlers(
启动请求处理程序,
ErfasseSpieleranzahlHandler,
汉德勒,
取消并停止IntentHandler,
SessionEndRequestHandler,
IntentReflectorHandler,//确保IntentReflectorHandler是最后一个,这样它就不会覆盖自定义的意图处理程序
)
.AddErrorHandler(
错误处理程序,
)

.lambda()您正在注销失败位置的堆栈跟踪,您是否尝试在cloudwatch日志中查找错误,因为它会缩小范围


虽然我可以立即看到您的插槽名为
Spieleranzahl
,但在您的代码中,当您尝试访问它时,您使用
Spieleranzahl
您正在注销失败位置的堆栈跟踪,您是否尝试在cloudwatch日志中查找错误,因为它会缩小范围
//ErfasseSpieleranzahlHandler
const ErfasseSpieleranzahlHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'ErfasseSpieleranzahl';
    },
    handle(handlerInput) {
        const spieleranzahl = handlerInput.requestEnvelope.request.intent.slots.Spieleranzahl.value;

        const speakOutput = `Ok ${spieleranzahl} Spieler, wie viele Punkte sollen gespielt werden?`;
        return handlerInput.responseBuilder
            .speak(speakOutput)
            //.reprompt(repromtText)
            .getResponse();
    }
};