Run exports.handle in AnswerIntentHandler - node.js - alexa skill












1















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();

},


};









share|improve this question





























    1















    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();

    },


    };









    share|improve this question



























      1












      1








      1








      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();

      },


      };









      share|improve this question
















      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();

      },


      };






      node.js amazon-dynamodb alexa-skills-kit






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 8:58









      D.Mendes

      11810




      11810










      asked Nov 15 '18 at 8:32









      Lukas SeegerLukas Seeger

      61




      61
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You should not put the code in the exports.handler. Please take a look at this example (the DynamoDB support code is in the helpers.js file). As a coincidence it's also working with colors.



          If the data you're storing is associated to each skill user (eg. a user attribute) a much easier way to do DynamoDB persistence is to use ASK persistent attributes (already supported in the ASK SDK).






          share|improve this answer
























          • Thank you for your answer! I must admit, that I am very new to coding and I got a little bit lost in the code you provided. You want me to put the whole DynamoDB connection into another file and then call this file with my Alexa Skill code right? Is it possible for you to provide an easy example to just call another file in node.js (like calling the helpers.js in your case) and provide this code with the data which needs to be wirtten into the DynamoDB? Thanks again!

            – Lukas Seeger
            Nov 19 '18 at 6:22













          • Lukas I'm afraid that's out of scope of what I do here in Stackoverflow (mostly Alexa skill development). I recommend you try to find more material online to learn javascript!

            – German
            Nov 28 '18 at 3:52



















          0














          I tried to edit the code and put the whole DynamoDB posting to another file called dynamodb.js. This is the content:



          const AWS         = require('aws-sdk');
          const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});

          exports.handle = function(e, ctx, callback) {

          var params = {
          Item: {
          date: Date.now(),
          message: "This hopefully works"

          },

          TableName: 'alexa_farbe'

          };

          docClient.put(params, function(err, data) {
          if (err) {
          console.log("Error", err);
          } else {
          console.log("Success", data);
          }
          });
          };


          I just want to write the date and an example phrase into my DynamoDB.



          To trigger this function, I tried to implement some kind of "runScript" into my AnswerIntentHandler of my Alexa Skill.
          But it doesn't seem to trigger the file. Can you give me some advice whats wrong with this code and how to call another node.js file from the AnswerIntent.
          Here is my edited AnswerIntent:



          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;
          let number = slots['FarbAuswahl'].value;
          let 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!`;

          module.runScript('./some-script.js', function (err) {
          if (err) throw err;
          console.log('finished running some-script.js');
          });



          return handlerInput.responseBuilder
          .speak(speechText)
          .withSimpleCard('Ausgewählte Farbe:', speechText)
          .getResponse();

          },

          };





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315224%2frun-exports-handle-in-answerintenthandler-node-js-alexa-skill%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You should not put the code in the exports.handler. Please take a look at this example (the DynamoDB support code is in the helpers.js file). As a coincidence it's also working with colors.



            If the data you're storing is associated to each skill user (eg. a user attribute) a much easier way to do DynamoDB persistence is to use ASK persistent attributes (already supported in the ASK SDK).






            share|improve this answer
























            • Thank you for your answer! I must admit, that I am very new to coding and I got a little bit lost in the code you provided. You want me to put the whole DynamoDB connection into another file and then call this file with my Alexa Skill code right? Is it possible for you to provide an easy example to just call another file in node.js (like calling the helpers.js in your case) and provide this code with the data which needs to be wirtten into the DynamoDB? Thanks again!

              – Lukas Seeger
              Nov 19 '18 at 6:22













            • Lukas I'm afraid that's out of scope of what I do here in Stackoverflow (mostly Alexa skill development). I recommend you try to find more material online to learn javascript!

              – German
              Nov 28 '18 at 3:52
















            0














            You should not put the code in the exports.handler. Please take a look at this example (the DynamoDB support code is in the helpers.js file). As a coincidence it's also working with colors.



            If the data you're storing is associated to each skill user (eg. a user attribute) a much easier way to do DynamoDB persistence is to use ASK persistent attributes (already supported in the ASK SDK).






            share|improve this answer
























            • Thank you for your answer! I must admit, that I am very new to coding and I got a little bit lost in the code you provided. You want me to put the whole DynamoDB connection into another file and then call this file with my Alexa Skill code right? Is it possible for you to provide an easy example to just call another file in node.js (like calling the helpers.js in your case) and provide this code with the data which needs to be wirtten into the DynamoDB? Thanks again!

              – Lukas Seeger
              Nov 19 '18 at 6:22













            • Lukas I'm afraid that's out of scope of what I do here in Stackoverflow (mostly Alexa skill development). I recommend you try to find more material online to learn javascript!

              – German
              Nov 28 '18 at 3:52














            0












            0








            0







            You should not put the code in the exports.handler. Please take a look at this example (the DynamoDB support code is in the helpers.js file). As a coincidence it's also working with colors.



            If the data you're storing is associated to each skill user (eg. a user attribute) a much easier way to do DynamoDB persistence is to use ASK persistent attributes (already supported in the ASK SDK).






            share|improve this answer













            You should not put the code in the exports.handler. Please take a look at this example (the DynamoDB support code is in the helpers.js file). As a coincidence it's also working with colors.



            If the data you're storing is associated to each skill user (eg. a user attribute) a much easier way to do DynamoDB persistence is to use ASK persistent attributes (already supported in the ASK SDK).







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 18 '18 at 20:54









            GermanGerman

            7,39042947




            7,39042947













            • Thank you for your answer! I must admit, that I am very new to coding and I got a little bit lost in the code you provided. You want me to put the whole DynamoDB connection into another file and then call this file with my Alexa Skill code right? Is it possible for you to provide an easy example to just call another file in node.js (like calling the helpers.js in your case) and provide this code with the data which needs to be wirtten into the DynamoDB? Thanks again!

              – Lukas Seeger
              Nov 19 '18 at 6:22













            • Lukas I'm afraid that's out of scope of what I do here in Stackoverflow (mostly Alexa skill development). I recommend you try to find more material online to learn javascript!

              – German
              Nov 28 '18 at 3:52



















            • Thank you for your answer! I must admit, that I am very new to coding and I got a little bit lost in the code you provided. You want me to put the whole DynamoDB connection into another file and then call this file with my Alexa Skill code right? Is it possible for you to provide an easy example to just call another file in node.js (like calling the helpers.js in your case) and provide this code with the data which needs to be wirtten into the DynamoDB? Thanks again!

              – Lukas Seeger
              Nov 19 '18 at 6:22













            • Lukas I'm afraid that's out of scope of what I do here in Stackoverflow (mostly Alexa skill development). I recommend you try to find more material online to learn javascript!

              – German
              Nov 28 '18 at 3:52

















            Thank you for your answer! I must admit, that I am very new to coding and I got a little bit lost in the code you provided. You want me to put the whole DynamoDB connection into another file and then call this file with my Alexa Skill code right? Is it possible for you to provide an easy example to just call another file in node.js (like calling the helpers.js in your case) and provide this code with the data which needs to be wirtten into the DynamoDB? Thanks again!

            – Lukas Seeger
            Nov 19 '18 at 6:22







            Thank you for your answer! I must admit, that I am very new to coding and I got a little bit lost in the code you provided. You want me to put the whole DynamoDB connection into another file and then call this file with my Alexa Skill code right? Is it possible for you to provide an easy example to just call another file in node.js (like calling the helpers.js in your case) and provide this code with the data which needs to be wirtten into the DynamoDB? Thanks again!

            – Lukas Seeger
            Nov 19 '18 at 6:22















            Lukas I'm afraid that's out of scope of what I do here in Stackoverflow (mostly Alexa skill development). I recommend you try to find more material online to learn javascript!

            – German
            Nov 28 '18 at 3:52





            Lukas I'm afraid that's out of scope of what I do here in Stackoverflow (mostly Alexa skill development). I recommend you try to find more material online to learn javascript!

            – German
            Nov 28 '18 at 3:52













            0














            I tried to edit the code and put the whole DynamoDB posting to another file called dynamodb.js. This is the content:



            const AWS         = require('aws-sdk');
            const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});

            exports.handle = function(e, ctx, callback) {

            var params = {
            Item: {
            date: Date.now(),
            message: "This hopefully works"

            },

            TableName: 'alexa_farbe'

            };

            docClient.put(params, function(err, data) {
            if (err) {
            console.log("Error", err);
            } else {
            console.log("Success", data);
            }
            });
            };


            I just want to write the date and an example phrase into my DynamoDB.



            To trigger this function, I tried to implement some kind of "runScript" into my AnswerIntentHandler of my Alexa Skill.
            But it doesn't seem to trigger the file. Can you give me some advice whats wrong with this code and how to call another node.js file from the AnswerIntent.
            Here is my edited AnswerIntent:



            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;
            let number = slots['FarbAuswahl'].value;
            let 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!`;

            module.runScript('./some-script.js', function (err) {
            if (err) throw err;
            console.log('finished running some-script.js');
            });



            return handlerInput.responseBuilder
            .speak(speechText)
            .withSimpleCard('Ausgewählte Farbe:', speechText)
            .getResponse();

            },

            };





            share|improve this answer




























              0














              I tried to edit the code and put the whole DynamoDB posting to another file called dynamodb.js. This is the content:



              const AWS         = require('aws-sdk');
              const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});

              exports.handle = function(e, ctx, callback) {

              var params = {
              Item: {
              date: Date.now(),
              message: "This hopefully works"

              },

              TableName: 'alexa_farbe'

              };

              docClient.put(params, function(err, data) {
              if (err) {
              console.log("Error", err);
              } else {
              console.log("Success", data);
              }
              });
              };


              I just want to write the date and an example phrase into my DynamoDB.



              To trigger this function, I tried to implement some kind of "runScript" into my AnswerIntentHandler of my Alexa Skill.
              But it doesn't seem to trigger the file. Can you give me some advice whats wrong with this code and how to call another node.js file from the AnswerIntent.
              Here is my edited AnswerIntent:



              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;
              let number = slots['FarbAuswahl'].value;
              let 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!`;

              module.runScript('./some-script.js', function (err) {
              if (err) throw err;
              console.log('finished running some-script.js');
              });



              return handlerInput.responseBuilder
              .speak(speechText)
              .withSimpleCard('Ausgewählte Farbe:', speechText)
              .getResponse();

              },

              };





              share|improve this answer


























                0












                0








                0







                I tried to edit the code and put the whole DynamoDB posting to another file called dynamodb.js. This is the content:



                const AWS         = require('aws-sdk');
                const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});

                exports.handle = function(e, ctx, callback) {

                var params = {
                Item: {
                date: Date.now(),
                message: "This hopefully works"

                },

                TableName: 'alexa_farbe'

                };

                docClient.put(params, function(err, data) {
                if (err) {
                console.log("Error", err);
                } else {
                console.log("Success", data);
                }
                });
                };


                I just want to write the date and an example phrase into my DynamoDB.



                To trigger this function, I tried to implement some kind of "runScript" into my AnswerIntentHandler of my Alexa Skill.
                But it doesn't seem to trigger the file. Can you give me some advice whats wrong with this code and how to call another node.js file from the AnswerIntent.
                Here is my edited AnswerIntent:



                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;
                let number = slots['FarbAuswahl'].value;
                let 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!`;

                module.runScript('./some-script.js', function (err) {
                if (err) throw err;
                console.log('finished running some-script.js');
                });



                return handlerInput.responseBuilder
                .speak(speechText)
                .withSimpleCard('Ausgewählte Farbe:', speechText)
                .getResponse();

                },

                };





                share|improve this answer













                I tried to edit the code and put the whole DynamoDB posting to another file called dynamodb.js. This is the content:



                const AWS         = require('aws-sdk');
                const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});

                exports.handle = function(e, ctx, callback) {

                var params = {
                Item: {
                date: Date.now(),
                message: "This hopefully works"

                },

                TableName: 'alexa_farbe'

                };

                docClient.put(params, function(err, data) {
                if (err) {
                console.log("Error", err);
                } else {
                console.log("Success", data);
                }
                });
                };


                I just want to write the date and an example phrase into my DynamoDB.



                To trigger this function, I tried to implement some kind of "runScript" into my AnswerIntentHandler of my Alexa Skill.
                But it doesn't seem to trigger the file. Can you give me some advice whats wrong with this code and how to call another node.js file from the AnswerIntent.
                Here is my edited AnswerIntent:



                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;
                let number = slots['FarbAuswahl'].value;
                let 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!`;

                module.runScript('./some-script.js', function (err) {
                if (err) throw err;
                console.log('finished running some-script.js');
                });



                return handlerInput.responseBuilder
                .speak(speechText)
                .withSimpleCard('Ausgewählte Farbe:', speechText)
                .getResponse();

                },

                };






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 19 '18 at 7:40









                Lukas SeegerLukas Seeger

                61




                61






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315224%2frun-exports-handle-in-answerintenthandler-node-js-alexa-skill%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python