我目前正在学习如何开发Alexa技能,并希望创建一种简单的技能来询问用户的姓名,以及在获得姓名时-该姓名可以写入DynamoDB表中。下面的代码仅用于设置名称部分,并且我有一些代码尝试将其写入表中。不幸的是,当我运行该技能时,我只会看到“请求的技能的响应存在问题”的错误。
任何人都可以看到问题出在下面或什么可能导致了该问题吗?谢谢!
function setNameInSession(intent, session, callback) {
const cardTitle = intent.name;
const nameSlot = intent.slots.Name;
let repromptText = '';
let sessionAttributes = {};
const shouldEndSession = false;
let speechOutput = '';
if (nameSlot) {
const name = nameSlot.value;
sessionAttributes = createNameAttributes(name);
speechOutput = `Great, thanks ${name}. You can ask me ` +
"your favorite color by saying, what's my favorite color?";
repromptText = "You can ask me your favorite color by saying, what's my favorite color?";
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'eu-west-1'});
// Create the DynamoDB service object
var ddb = new AWS.DynamoDB({apiVersion: '2012-10-08'});
var params = {
TableName: 'myTestTable',
Item: {
'timeStamp' : {S: 'Richard Roe'}
}
};
ddb.putItem(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data);
}
});
} else {
speechOutput = "I'm not sure what your favorite color is. Please try again.";
repromptText = "I'm not sure what your favorite color is. You can tell me your " +
'favorite color by saying, my favorite color is red';
}
callback(sessionAttributes,
buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}