question

Fabián Romo avatar image
Fabián Romo asked

What type of variable is intent.slots.myIntent.value in the source code of a lambda?

Hi.

I'm doing a skill in the Alexa development console.

An intent within the skill is as follows:


activates the output {mySlot} where mySlot is of type AMAZON.NUMBER


I have taken a lambda function provided by the manufacturer of a microntroller from an example.


This function is a JS file where I have written a function for the aforementioned intent as follows:


function setMyOutPut(intent, session, callback)

{

   ...

   const desiredState = intent.slots.mySlot.value;

  if ((desiredState === 1))  {
    powerOn = 1;
  }

  else if ((desiredState === 2))
  {
    powerOn = 2;
  }

  else if ((desiredState === 3))
  {
    powerOn = 3;
  }

  else
  {

           speechOutput = "There are only three outputs to activate";

           repromptText = "I did not understand the exit number, please try again';

           callback(sessionAttributes, buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));

  }

  ...

}


When from Alexa I execute the Skill and the intent, when I say "activates the output one", a confirmation Intent is executed in which Alexa responds "The output has been activated correctly".

But if I say, for example "activate the output seven", in the same way it responds that it has been activated correctly.


Or there are times when I say "activates the output three" and the else is produced and it answers "There are only three outputs to activate".


So what I suspect is that intent.slots.mySlot.value is not a numeric variable.


Any suggestions or comments?


lambdaalexa skillsjavascript
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Gaetano@Amazon avatar image
Gaetano@Amazon answered

Hello and thanks for posting.

Can you please add the following line of code and share the output:

console.log(JSON.stringify(handlerInput.requestEnvelope.request.intent.slots))

Please do that for both the "output one" and "output seven" interactions.

Regards,
Gaetano

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andy Whitworth avatar image
Andy Whitworth answered

You'll make your life much easier if you add debug logging in your skill to output the JSON for all intents received by your skill. You'll then be able to see the slot data passed and determe what's happening.

But in this case, if you check the Amazon reference documentation then you'll see that all slot values are passed as strings, including AMAZON.NUMBER slots.

https://developer.amazon.com/en-US/docs/alexa/custom-skills/request-types-reference.html#slotvalue-object

Here's an example from one of my skills:

The intent definition:

        {
          "name": "PlayerCountIntent",
          "slots": [{
            "name": "playerCount",
            "type": "AMAZON.NUMBER",
            "samples": ["just {playerCount}",
              "{playerCount} of us",
              "{playerCount} people",
              "{playerCount}"
            ]
          }]

Results in this JSON request:

        "intent": {            
           "name": "PlayerCountIntent",            
           "confirmationStatus": "NONE",            
           "slots": {                
              "playerCount": {                    
              "name": "playerCount",                    
              "value": "4",                    
              "confirmationStatus": "NONE",                    
              "source": "USER"                
              }            
          }        
       }


So either change your checks to === "1" etc or use an implicit comparison with just two equals characters so that javascript will match "1" with 1

if ((desiredState == 1)) {

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.