1

因此,当我在本地运行时,我有多个调用链接所有工作并将更新发布到谷歌电子表格,但是当我尝试在 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();
        });
};

我的本地终端输出: 2017-06-28_00-21-53

AWS 输出使用与请求完全相同的 JSON: 2017-06-28_00-24-45

我的节点版本都是 6.10,我有两个 alexa-app-server/我的应用程序使用 alexa-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": {}
}
4

1 回答 1

1

所以在 PSU 一位很棒的朋友的帮助下,我想通了。

我实际上是在返回我的代码,当 Lambda 看到该返回时,它会杀死该函数。在本地计算机上运行时,它会返回,但不会终止进程,因此其余代码仍将运行。

为了解决这个问题,我将所有内容都包装在一个 Promise 中,然后用 .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();
        });
    } 

和更新表:

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();
            });
    });
于 2017-06-28T18:18:42.300 回答