I am currently developing an Amazon Alexa Skill, which asks the user for a color. The user enters the color by voice and Alexa checks, if the color is in a defined array of values. If that is the case, it returns the color name with an ID. Now this works as intended, but now I would like to put this value in AWS DynamoDB. I read some tutorials on how to connect and to write into DynamoDB using AWS Lambda (Runtime Node.js 8.10) So, in the following code, you can see my AnswerIntentHandler of my Alexa Skill. I included the exports. handle function to write the value of the ID of the color and the name of the color in the table called "alexa_farbe". But when I simulate the Skill with the Alexa Skill developer, the code only gives out the "speechText" and doesn't seem to run the code to write into the DynamoDB. Perhaps it is not possible to run a exports.handle in the AnswerIntentHanlder or is it? I am very new to this topic so I am not really sure where the mistake in this code is. I provide the code of my AnswerIntentHandler, but I can also provide the whole code of the Alexa Skill. I hope somebody can give me a hint what to to.
const AnswerIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AnswerIntent';
},
handle(handlerInput) {
const slots = handlerInput.requestEnvelope.request.intent.slots;
const number = slots['FarbAuswahl'].value;
var numberid = slots['FarbAuswahl'].resolutions.resolutionsPerAuthority[0].values[0].value.id; /* ID der Farbe auslesen */
var speechText = 0;
speechText = `Prima, ich stelle die Farbe ${number} mit der ID ${numberid} ein!`;
/* Ab hier Versuch in die Datenbank DynamoDB zu schreiben */
exports.handle = function(e, etx, callback) {
var params = {
Item: {
ID: '${numberid}',
Farbname: '${number}'
},
TableName: 'alexa_farbe'
};
docClient.put(params, function(err, data) {
if(err) {
callback(err, null);
} else {
callback(null, data);
}
});
};
return handlerInput.responseBuilder
.speak(speechText)
.withSimpleCard('Ausgewählte Farbe:', speechText)
.getResponse();
},
};