Javascript Alexa skill在developer.amazon上工作,但不在设备上工作?
好的,这需要详细说明: 首先,当我在developer.amazon.com中询问“DeparmentLocation”的意图时,它可以正常工作。当我使用真正的设备时,它会调用“unhandledIntent”。 其次,当重新提示时,它确实会工作,如下所示: “嘿,Alexa,问问调用名。”在它回复未经处理的消息之前,不要说任何话。然后,我可以正常地说出这句话,它就会做出反应。 第三也是最后一点,它是以“设施定位”为目的的。我不知道发生了什么,或者有什么不同。 这是代码。 谢谢Javascript Alexa skill在developer.amazon上工作,但不在设备上工作?,javascript,aws-lambda,alexa,alexa-skills-kit,alexa-skill,Javascript,Aws Lambda,Alexa,Alexa Skills Kit,Alexa Skill,好的,这需要详细说明: 首先,当我在developer.amazon.com中询问“DeparmentLocation”的意图时,它可以正常工作。当我使用真正的设备时,它会调用“unhandledIntent”。 其次,当重新提示时,它确实会工作,如下所示: “嘿,Alexa,问问调用名。”在它回复未经处理的消息之前,不要说任何话。然后,我可以正常地说出这句话,它就会做出反应。 第三也是最后一点,它是以“设施定位”为目的的。我不知道发生了什么,或者有什么不同。 这是代码。 谢谢 var doc
var doc = require('dynamodb-doc');
var db = new doc.DynamoDB();
var Alexa = require('alexa-sdk');
exports.handler = function(event, context) {
var alexa = Alexa.handler(event, context);
var handlers = {
'sessionStartedRequest' : function(){
this.emit(':talk', "welcome.")
},
'AMAZON.StopIntent': function() {
this.emit(':tell', "Goodbye!");
},
'AMAZON.CancelIntent': function() {
this.emit(':tell', "Goodbye!");
},
'Unhandled': function() {
this.emit(':ask', "I'm sorry. I didn't get that. Could you repeat it?", "Ask me a question.");
},
'SessionEndedRequest': function() {
this.emit(":tell", "Goodbye!");
},
'DepartmentLocationIntent': function () {
var name = "";
if (this.event.request.intent.slots.department.value) {
name = this.event.request.intent.slots.department.value.toLowerCase().trim();
}
var key = {
'name': name
};
var tableName = "Department";
var params = {
TableName: tableName,
Key: key,
ProjectionExpression: 'loc'
};
db.getItem(params, function (err, data) {
//alexa.emit(":tell", name);
if (err) {
console.log(err);
//alexa.emit(':tell', "Sorry! I did not catch that!");
alexa.emit(':tell', err);
} else {
var loc = JSON.stringify(data.Item.loc);
alexa.emit(':tell', "The " + name + " department is in " + loc);
}
}, context.done);
},
'FacilityLocationIntent': function() {
var name = "";
if (this.event.request.intent.slots.facility.value) {
name = this.event.request.intent.slots.facility.value.toLowerCase().trim();
}
var key = {
'name': name
};
var tableName = "Facility";
var params = {
TableName: tableName,
Key: key,
ProjectionExpression: 'loc'
};
db.getItem(params, function(err, data) {
if (err) {
console.log(err);
alexa.emit(':tell', "Sorry! This facility does not exist!");
} else {
var response = JSON.stringify(data.Item.loc);
alexa.emit(':tell', name + " is located in " + response);
}
}, context.done);
}
};
alexa.registerHandlers(handlers);
alexa.execute();
};
`bDir
我不知道您是否仍在寻求解决方案,但我认为您的问题在于代码的嵌套。
试着把这些东西从“exports.handler”中分离出来,因为它更干净,更容易使用,正如AWS lambda指南所说的。
所以试试这个:
exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context, callback);
alexa.registerHandlers(handlers);
alexa.execute();
};
然后在不同的处理器下面
var handlers = {
'sessionStartedRequest' : function(){
this.emit(':talk', "welcome.")
},
'AMAZON.StopIntent': function() {
this.emit(':tell', "Goodbye!");
},
'AMAZON.CancelIntent': function() {
this.emit(':tell', "Goodbye!");
},
'Unhandled': function() {
this.emit(':ask', "I'm sorry. I didn't get that. Could you repeat it?", "Ask me a question.");
},
'SessionEndedRequest': function() {
this.emit(":tell", "Goodbye!");
},
'DepartmentLocationIntent': function () {
var name = "";
if (this.event.request.intent.slots.department.value) {
name = this.event.request.intent.slots.department.value.toLowerCase().trim();
}
var key = {
'name': name
};
var tableName = "Department";
var params = {
TableName: tableName,
Key: key,
ProjectionExpression: 'loc'
};
db.getItem(params, function (err, data) {
//alexa.emit(":tell", name);
if (err) {
console.log(err);
//alexa.emit(':tell', "Sorry! I did not catch that!");
alexa.emit(':tell', err);
} else {
var loc = JSON.stringify(data.Item.loc);
alexa.emit(':tell', "The " + name + " department is in " + loc);
}
}, context.done);
},
'FacilityLocationIntent': function() {
var name = "";
if (this.event.request.intent.slots.facility.value) {
name = this.event.request.intent.slots.facility.value.toLowerCase().trim();
}
var key = {
'name': name
};
var tableName = "Facility";
var params = {
TableName: tableName,
Key: key,
ProjectionExpression: 'loc'
};
db.getItem(params, function(err, data) {
if (err) {
console.log(err);
alexa.emit(':tell', "Sorry! This facility does not exist!");
} else {
var response = JSON.stringify(data.Item.loc);
alexa.emit(':tell', name + " is located in " + response);
}
}, context.done);
}
};
希望这能解决你的问题