在dynamodb中获取单个alexa响应的时间戳

Getting timestamp of individual alexa responses in dynamodb

我正在创建一个 Alexa factskill,要求用户提供一些关于他们健康的信息,用户会根据不同区域的疼痛程度给出 1-10 的分数。然后我将数据输入 DynamoDB table,它存储四个健康问题(肿胀、感觉、睡眠、呼吸)和用户 ID 的信息(满分 10 分)。但是,这些条目没有给出创建时间的时间戳。我想知道是否有一种方法可以为每个健康问题回复制作一个时间戳,但也可以为整个条目制作一个时间戳会有所帮助。我是否必须使用任何外部 SDK,因为我正在查找 DynamoDB 文档并且没有找到任何添加时间戳的方法。

下面是用于我的 Alexa 技能的 Lambda 函数的 index.js 代码。

'use strict';
const Alexa = require('alexa-sdk');

const SKILL_NAME = 'Home Assist';
const HELP_MESSAGE = 'You can say I want to input my data';
const HELP_REPROMPT = 'What can I help you with?';
const STOP_MESSAGE = 'Goodbye!';


const handlers = {
    'LaunchRequest': function () {
        this.emit('HomeAssistQuestions');
    },
    'HomeAssistQuestions': function () {
        this.attributes.healthscores = {
            'patientID' : 0,
            'scores': {
                'feeling': {
                    'score': 0
                },
                'sleeping': {
                    'score': 0
                },
                'breathing': {
                    'score': 0
                },
                'swollen': {
                    'score': 0
                }
            }
        };

        if(this.event.request.dialogState !== 'COMPLETED'){
            this.emit(':delegate');
        }
        else{
            const feelingScore = this.event.request.intent.slots.feelingRating.value;
            const sleepingScore = this.event.request.intent.slots.sleepingRating.value;
            const breathingScore = this.event.request.intent.slots.breathingRating.value;
            const swollenScore = this.event.request.intent.slots.SwollenRating.value;
            const id = this.event.request.intent.slots.id.value;


            this.attributes.healthscores.patientID = id;
            this.attributes.healthscores.scores['feeling'].score = feelingScore;
            this.attributes.healthscores.scores['sleeping'].score = sleepingScore;
            this.attributes.healthscores.scores['breathing'].score = breathingScore;
            this.attributes.healthscores.scores['swollen'].score = swollenScore;

            this.response.speak("Health Scores Recorded");
            this.emit(':responseReady');
        }


    },
    'AMAZON.HelpIntent': function () {
        const speechOutput = HELP_MESSAGE;
        const reprompt = HELP_REPROMPT;

        this.response.speak(speechOutput).listen(reprompt);
        this.emit(':responseReady');
    },
    'AMAZON.CancelIntent': function () {
        this.response.speak(STOP_MESSAGE);
        this.emit(':responseReady');
    },
    'AMAZON.StopIntent': function () {
        this.response.speak(STOP_MESSAGE);
        this.emit(':responseReady');
    },
    'SessionEndedRequest': function(){
        this.emit('saveState', true);
    }
};

exports.handler = function (event, context, callback) {
    const alexa = Alexa.handler(event, context, callback);
    alexa.dynamoDBTableName = 'HealthScores';
    alexa.APP_ID = "amzn1.ask.skill.d5b8d597-eb50-41c6-a22d-b0f18c23b544";
    alexa.registerHandlers(handlers);
    alexa.execute();
};

您可以尝试这样的操作:

...  
this.attributes.healthscores.scores['swollen'].score = swollenScore;
this.attributes.healthscores.timestamp = Date.now();

this.response.speak("Health Scores Recorded");  
...