1
votes

I am new to node.js and trying to develop a sample alexa skill based on lambda function.My launch request function is like this.

    'LaunchRequest': function () {
     const speechOutput = HELP_MESSAGE;

    console.log("Inside launch");
    const reprompt = "Welcome to US Facts. Do you want a new fact";

    this.response.speak(speechOutput).listen(reprompt);
    this.emit(':responseReady');
   // this.emit('GetmyFactIntent');
},

I want to capture what is the value user uttered? The speechoutput is emitted fine but based on user value entered\uttered I want to call different Intents. How to do that?

Also when I test lambda function..the console.log stmt is never printed. It prints fine from GetmyFactIntent method.

2

2 Answers

0
votes

In Alexa interaction modal, create different intents with many sample utterances for each Intent. If you want to get any value from the user, add slots with the utterances i.e., "my favorite color is green" Here green is the user input and you can get from slots.

Below is the interaction model for Quiz Intent where you don't need any slots.

{
          "name": "QuizIntent",
          "samples": [
            "start a quiz",
            "start a quiz game",
            "and start a quiz",
            "and quiz me",
            "for a quiz",
            "a quiz"
          ],
          "slots": []
        }

But answer Intent will need slots to get the answer from the user reply. In below user interaction model user will give the state name and Alexa will get it from inbuild slot type AMAZON.US_STATE

{
          "name": "AnswerIntent",
          "samples": ["{StateName}"],
          "slots": [
            {
              "name": "StateName",
              "type": "AMAZON.US_STATE",
              "samples": []
            } ]
}

you can get the slot value in Node.js lambda function using below line of code

let slots = this.event.request.intent.slots;
let stateName = this.event.request.intent.slots["StateName"];

refer this tutorial for more information https://github.com/alexa/skill-sample-nodejs-quiz-game

0
votes

this.event.request.intent.slots.Answer.value;

We need to define slots in intent and then capture that value.