0
votes

I am using Alexa Node.js sdk, to implement a skill. On session start (at LaunchRequest intent), I want to store some variables in the session attributes. As per the blog here, I am using this.attributes.key to store the session attributes.

const handlers = {
    'LaunchRequest': function () {
        database.startSession()
            .then(data => {
                // console.log(data); // data does have token
                this.attributes.token=data.token;
                // this.attributes['token']=data.token; // Tried this too
                this.emit(':ask', responses.launch, responses.launchReprompt);
            })
            .catch(err => {
                console.error(err);
                this.emit(":ask", responses.error);
            });
    }, 
    .... More handlers
}

However, the on launch command, I get this error,

There was a problem with the requested skill's response

I see no error in logs.

This is my response (as visible in alexa test developer console)

{
    "body": {
        "version": "1.0",
        "response": {
            "outputSpeech": {
                "type": "SSML",
                "ssml": "<speak> Ok, exiting App. </speak>"
            },
            "shouldEndSession": true
        },
        "sessionAttributes": {},
        "userAgent": "ask-nodejs/1.0.25 Node/v8.10.0"
    }
}

As per here, the sessionAttributes should contain what I set as session variables using this.attributes, but this is somehow empty.

How can I resolve this?

Edit: If I comment out this.attributes line, I get the welcome message correctly.

This is my startSession function, if its helpful.

async function startSession() {
    return {
        token: await getToken(),
        ... More attributes
    };
}

Edit 2: Very wierd thing that I noticed. If I just do this.attributes.token="foobar", the session attribute gets set correctly. So I am assuming there is a problem with my async function. Note that console.log(data) still prints the data correctly with token attribute.

Edit 3: Cloudwatch logs

START RequestId: Version: $LATEST 2018-08-15T14:00:47.639Z Warning: Application ID is not set END RequestId: REPORT RequestId: Duration: 315.05 ms Billed Duration: 400 ms Memory Size: 128 MB Max Memory Used: 73 MB
START RequestId: Version: $LATEST 2018-08-15T14:00:47.749Z Warning: Application ID is not set 2018-08-15T14:00:48.564Z { token: 'token', filter: 'foobar'} END RequestId: REPORT RequestId: Duration: 849.98 ms Billed Duration: 900 ms Memory Size: 128 MB Max Memory Used: 74 MB START RequestId: Version: $LATEST 2018-08-15T14:00:49.301Z Warning: Application ID is not set END RequestId: REPORT RequestId: Duration: 0.72 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 74 MB

1
Can you paste your sample data of console.log(data)?Hardik Shah
{ token: '<token-value>', ... }Riken Shah
Can you share the error logged in cloudwatchjohndoe
There is no error, still shared the log, as it is displayed in cloudwatch.Riken Shah

1 Answers

1
votes

We found that the max size of the response object is 24kb, reference1, reference2, reference3.

My data size was way more than 24kb. Hence the session attributes did not get stored, and it resulted in exit intent. The solution is to store it in some db like DynamoDB.

Special credits to Will.