1

So I have multiple calls chained all working and posting the update to a google spreadsheet when I run locally, but when I try and run it on Lambda it just returns early without any errors.

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);
        }
);

and here's what updateSheet looks

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();
        });
};

my local terminal ouput: 2017-06-28_00-21-53

AWS output using the exact same JSON for the request: 2017-06-28_00-24-45

My node versions are both 6.10 and I have both alexa-app-server/my app using alexa-app: "^4.0.0"

local response:

{
  "version": "1.0",
  "response": {
    "directives": [],
    "shouldEndSession": true,
    "outputSpeech": {
      "type": "SSML",
      "ssml": "<speak>Successfully logged</speak>"
    }
  },
  "sessionAttributes": {},
  "dummy": "text"
}

Lambda's empty:

{
  "version": "1.0",
  "response": {
    "directives": [],
    "shouldEndSession": true
  },
  "sessionAttributes": {}
}
Arafat Nalkhande
  • 11,078
  • 9
  • 39
  • 63
joshbenner851
  • 111
  • 1
  • 12

1 Answers1

1

So with help of an awesome friend at PSU I figured it out.

I was actually returning my code and when Lambda sees that return it kills the function. When running on your local machine, it'll return, but not kill the process and therefore the rest of the code will still run.

To solve this, I wrapped everything in a promise and then returned that with a .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();
        });
    } 

and the 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();
            });
    });
joshbenner851
  • 111
  • 1
  • 12