首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Alexa应用程序在本地工作,在Lambda上提前返回

Alexa应用程序在本地工作,在Lambda上提前返回
EN

Stack Overflow用户
提问于 2017-06-28 13:46:43
回答 1查看 93关注 0票数 1

因此,当我在本地运行时,我有多个调用链接在一起工作,并将更新发布到google电子表格,但当我尝试在Lambda上运行它时,它只是提前返回,没有任何错误。

代码语言:javascript
复制
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的外观

代码语言:javascript
复制
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();
        });
};

我的本地终端输出:

对请求使用完全相同的JSON的AWS输出:

我的节点版本都是6.10,而且我的alexa- app -server/我的app都使用alexa-app:"^4.0.0“

本地响应:

代码语言:javascript
复制
{
  "version": "1.0",
  "response": {
    "directives": [],
    "shouldEndSession": true,
    "outputSpeech": {
      "type": "SSML",
      "ssml": "<speak>Successfully logged</speak>"
    }
  },
  "sessionAttributes": {},
  "dummy": "text"
}

Lambda为空:

代码语言:javascript
复制
{
  "version": "1.0",
  "response": {
    "directives": [],
    "shouldEndSession": true
  },
  "sessionAttributes": {}
}
EN

回答 1

Stack Overflow用户

发布于 2017-06-29 02:18:42

因此,在PSU一个很棒的朋友的帮助下,我找到了答案。

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

为了解决这个问题,我把所有东西都包装在一个promise中,然后用一个.then()

代码语言:javascript
复制
// 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:

代码语言:javascript
复制
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();
            });
    });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44794492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档