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



我正在创建一个Alexa事实技能,询问用户有关其健康状况的一些信息,用户根据不同区域的疼痛程度给出1-10分的回答。然后,我将数据输入到DynamoDB表中,该表存储了四个健康问题(肿胀、感觉、睡眠、呼吸(的信息(满分10分(和用户ID。然而,这些条目并没有给出创建时间的时间戳。我想知道是否有一种方法可以为每个健康问题的回答创建时间戳,但也可以为整个条目创建时间戳。我是否必须使用任何外部SDK,因为我在查找DynamoDB文档时没有找到任何添加时间戳的方法。

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

'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");  
...

最新更新