因此Alexa不能证明我们的技能,因为帐户未链接响应返回时出错并没有给出正确的命令。我将意图称为“ ErrorIntent”。仅在发话“ Alexa,打开{调用名称}”时发生。所有其他命令将显示卡,并在取消链接时说出正确的响应。我已经为此工作了一个星期,但无济于事。这是代码(我正在使用节点;错误部分用// THROWS ERROR标记):
"LaunchRequest": function () {
this.response.speak("Welcome to ThermaSol Steam! Some sample phrases you can use are: Alexa, tell smart shower to turn on. Or. Alexa, tell smart shower to turn on steam. A full list of commands that you can use with the ThermaSol skill can be found on your Thermasol device or in the skill card in the Alexa mobile app.");
this.emit(':responseReady');
},
"ErrorIntent": function () {
var speechOutput = "There seems to be a problem with your Thermasol skill. Please make sure the Thermasol skill is linked with your Thermasol device account. You can find more information on the Thermasol skill link card in the alexa mobile app.";
this.emit(':tellWithLinkAccountCard', speechOutput);
},
"Unhandled": function () {
this.response.speak("I don't know that Thermasol skill command. Please check out the full list of commands on your Thermasol device.");
this.emit(':responseReady');
}
};
exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
var paramsToRead = {
TableName: 'DeviceIdTable',
Key: {
'user_id' : {S: event.session.user.userId},
},
ProjectionExpression: 'device_id'
};
console.log("DynamoDB ParamsToRead: ", paramsToRead);
ddb.getItem(paramsToRead, function(err, data) {
console.log("Attempting DynamoDB ThermaTouch Device ID lookup");
if (err) {
console.log("Error", err);
this.event.request.intent.name = "ErrorIntent";
event.session.attributes['errorCode'] = 100;
alexa.execute();
} else {
console.log("Successful transaction, data is: ", data);
if(Object.keys(data).length === 0) {
console.log("Hitting DynamoDB Conditional");
var userRequestParams = {
"AccessToken": event.context.System.user.accessToken
};
console.log("Cognito AccessToken: ", userRequestParams);
if ( typeof event.context.System.user.accessToken === 'undefined'){
console.log("ACCESS TOKEN UNDEFINED");
console.log("INTENT REQUEST: ", event.request.intent.name);
event.request.intent.name = "ErrorIntent"; //THROWS ERROR
event.session.attributes['errorCode'] = 200;
alexa.execute();
}else{
console.log("HITITNG COGNITO");
cognitoidentityserviceprovider.getUser(userRequestParams,
function(err, data) {
console.log("Device ID was not in DynamoDB, attempting Cognito lookup");
if(err) {
console.log(err);
event.request.intent.name = "ErrorIntent";
event.session.attributes['errorCode'] = 200;
alexa.execute();
} else {
console.log("Succesful Transaction, data is: ", data);
data.UserAttributes.forEach(element => {
if(element.Name === "custom:thermaTouchDeviceId") {
var paramsToWrite = {
TableName: 'DeviceIdTable',
Item: {
'user_id' : {S: event.session.user.userId},
'device_id' : {S: element.Value}
}
};
console.log("paramsToWrite: ", paramsToWrite);
ddb.putItem(paramsToWrite, function(err, data) {
console.log("Attempting DynamoDB data save");
if (err) {
console.log(err);
event.request.intent.name = "ErrorIntent";
event.session.attributes['errorCode'] = 300;
alexa.execute();
} else {
console.log("Successful transaction, table stats: ", data);
event.session.attributes['deviceId'] = element.Value;
console.log("Device ID " + element.Value + " was added to session attributes");
alexa.execute();
}
});
}
});
}
});
}
} else {
console.log("Device ID was found in DynamoDB");
event.session.attributes['deviceId'] = data.Item.device_id.S;
console.log("Device ID " + data.Item.device_id.S + " was added to session attributes");
alexa.execute();
}
}
}); };
这是日志:
2019-08-28T18:36:03.127Z 2445fa56-0333-473d-b7a7-a93a6cd347b9 INFO
Uncaught exception: TypeError: Cannot read property 'name' of undefined
TypeError: Cannot read property 'name' of undefined
at Response.<anonymous> (/var/task/index.js:592:64)
at Request.<anonymous> (/var/runtime/node_modules/aws-
sdk/lib/request.js:364:18)
at Request.callListeners (/var/runtime/node_modules/aws-
sdk/lib/sequential_executor.js:106:20)
at Request.emit (/var/runtime/node_modules/aws-
sdk/lib/sequential_executor.js:78:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/var/runtime/node_modules/aws-
sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-
sdk/lib/state_machine.js:14:12)
at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/var/runtime/node_modules/aws-
sdk/lib/request.js:38:9)
at Request.<anonymous> (/var/runtime/node_modules/aws-
sdk/lib/request.js:685:12)
任何帮助将不胜感激!