因此,当我在本地运行时,我有多个链接所有工作并将更新发布到谷歌电子表格,但当我尝试在Lambda上运行它时,它只是提前返回而没有任何错误。
skillService.intent("sampleIntent", {
...
},
function(request,response){
var name = request.slot("NAME");
var category = request.slot("CATEGORY");
var event = request.slot("EVENT");
// slot used for any parts of conversation
var stepValue = request.slot('STEPVALUE');
var sampleHelper = getHelper(request);
// If it hasn't started, see if the user gave some slots and start from that step
if(!sampleHelper.started){
sampleHelper.determineStep(name, category, event);
}
sampleHelper.started = true;
// Did they provide all the necessary info?
if(sampleHelper.completed()){
// Handles reading out the menu, etc
return sampleHelper.updateSheet(response);
}
);
以及updateSheet的内容
SampleHelper.prototype.updateSheet = function(resp){
var name = this.observance[0].steps[0].value;
var category = this.observance[0].steps[1].value;
var event = this.observance[0].steps[2].value;
console.log("about to auth.");
return authorize(JSON.stringify(this.access_token))
.then(function(auth){
console.log("passed auth");
return getColumns(auth, name, category).then(function(){
console.log("get columns");
return updateSheet(auth,name,category,event).then(function(){
console.log("finished updating");
return resp.say("Successfully logged for " + name + " a " + category + " of " + event).send();
});
}).catch(function(err){
console.log("failed columns");
return resp.say(err).send();
});
})
.catch(function (err) {
console.log("Auth err: ", err);
return resp.say("There was an error authenticating. Please check your Alexa app for how to reconnect your google account.").send();
});
};
我的本地终端输出:
AWS输出使用与请求完全相同的JSON:
我的节点版本都是6.10,我使用alexa-app同时拥有alexa-app-server / my app:" ^ 4.0.0"
当地回应:
{
"version": "1.0",
"response": {
"directives": [],
"shouldEndSession": true,
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>Successfully logged</speak>"
}
},
"sessionAttributes": {},
"dummy": "text"
}
Lambda的空:
{
"version": "1.0",
"response": {
"directives": [],
"shouldEndSession": true
},
"sessionAttributes": {}
}
答案 0 :(得分:1)
所以在PSU的一位很棒的朋友的帮助下我明白了。
我实际上正在返回我的代码,当Lambda看到返回时它会杀死该函数。在本地计算机上运行时,它会返回,但不会终止进程,因此其余代码仍会运行。
为了解决这个问题,我将所有内容都包含在一个承诺中,然后使用.then()
返回// Did they provide all the necessary info?
if(sampleHelper.completed()){
// Handles reading out the menu, etc
return sampleHelper.updateSheet(response).then(function(data){
return response.say("Successfully logged for " + sampleHelper.getName() + " a " + sampleHelper.getCategory() + " of " + sampleHelper.getEvent()).send();
}).catch(function(err){
console.log(err);
return response.say("error").send();
});
}
和updateSheet:
return new Promise(function(resolve, reject) {
authorize(JSON.stringify(access_token))
.then(function (auth) {
console.log("passed auth");
getColumns(auth, name, category).then(function () {
console.log("get columns");
updateSheet(auth, name, category, event).then(function () {
console.log(new Date().getTime());
resolve("worked");
});
}).catch(function (err) {
console.log("failed columns");
throw "Failed columns";
// return resp.say(err).send();
});
})
.catch(function (err) {
throw err;
console.log("Auth err: ", err);
return resp.say("There was an error authenticating. Please check your Alexa app for how to reconnect your google account.").send();
});
});