I have a lambda function that is connected to an Alexa skill. At the start of the skill I want to store a string to dynamoDB. Therefore I call a function directly in the launch request (the function is called nameExport()). However the function is only stores something if I delete the "this.emit" command in the launch request. If I leave "this.emit" the skill is working but nothing is stored to the database. Below you find the code concerning LaunchRequest as well as the function to store into dynamoDB.
var config = require("config");
var Alexa = require("alexa-sdk");
var AWS = require("aws-sdk");
var Speech = require("ssml-builder");
var dynamodb = new AWS.DynamoDB();
let handlers = {
'LaunchRequest': function () {
nameExport("testName");
let speech = new Speech ();
speech.say("Welcome by Emotions.")
speech.pause("100ms")
speech.say("Do you want to assess your current emotion?")
let speechOutput = speech.ssml(true);
this.emit(":ask", speechOutput)
},
'Emotion': function () {
let speech = new Speech();
...
The nameExport function that should write the String into the database:
function nameExport(name) {
var tableName = "myinfo";
dynamodb.putItem({
"TableName": tableName,
"Item": {
"name": {
"S": name
}
}
}, function(err, data) {
if (err) {
//context.fail('ERROR: Dynamo failed: ' + err);
} else {
console.log('Dynamo Success: ' + JSON.stringify(data, null, ' '));
//context.succeed('SUCCESS');
}
});
};