会话属性的 Alexa 错误

Alexa error with session attributes

我正在使用 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,我正在使用 this.attributes.key 来存储会话属性。

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
}

但是,启动命令时出现此错误,

There was a problem with the requested skill's response

我在日志中没有看到任何错误。

这是我的回复(在 alexa 测试开发者控制台中可见)

{
    "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"
    }
}

per here 一样,sessionAttributes 应该包含我使用 this.attributes 设置为会话变量的内容,但不知何故这是空的。

我该如何解决这个问题?

编辑:如果我注释掉 this.attributes 行,我会正确收到欢迎消息。

这是我的 startSession 功能,如果有帮助的话。

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

编辑 2:我注意到非常奇怪的事情。如果我只是做 this.attributes.token="foobar",会话属性设置正确。所以我假设我的 async 函数有问题。请注意,console.log(data) 仍会使用 token 属性正确打印数据。

编辑 3:Cloudwatch 日志

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

我们发现 response 对象的最大大小为 24kb, reference1, reference2, reference3.

我的 data 尺寸比 24kb 大得多。因此会话属性没有被存储,它导致 exit 意图。解决方案是将其存储在某些数据库中,例如 DynamoDB.

特别感谢 Will