1
votes

I am relatively new to AWS and Alexa skills. I am building a simple custom skill that gives you a dressing advice depending on the weather.

I have 2 custom intents : dressingTodayIntent & dressingTomorrowIntent. In the Service Simulator of the developer portal, my two intents don't work, I do get a lambda response though, but with an undefined outputSpeech, like this:

{ 
 "version": "1.0", 
 "response": { 
   "outputSpeech": { 
     "type": "SSML", 
     "ssml": "<speak> undefined </speak>" 
   }, 
   "card": null, 
   "reprompt": null, 
   "speechletResponse": { 
     "outputSpeech": { 
       "id": null, 
       "ssml": "<speak> undefined </speak>" 
     }, 
     "card": null, 
     "directives": null, 
     "reprompt": null, 
     "shouldEndSession": true 
   } 
 }, 
 "sessionAttributes": {} 
}

Could it be a scope issue in my intent code?

'DressingTodayIntent': function() {
    var dressingAdvice;
    var speechOutput = getJSON('https://api.darksky.net/forecast/9e0495a835ed823a705a9a567eee982a/48.861317,2.348764?units=si&exclude=currently,minutely,hourly,alerts,flags',
        function(err, forecast) {
            if (err) {
              console.log('Error occurred while trying to retrieve weather data', err);
            } else {
              dressingAdvice = getDressingAdvice(forecast, true);
              console.log("one " + dressingAdvice);
            }
            console.log("two " + dressingAdvice);
            return dressingAdvice;
        });
    console.log("three " + speechOutput);
    this.response.cardRenderer("Your dressing advice for today:", speechOutput);
    this.response.speak(speechOutput);
    this.emit(':responseReady');
},

In AWS Lambda, I see a correct output for the first 2 logs, and an error for the 3rd one:

  • first log: "one " + dressingAdvice, as expected
  • second log: "two " + dressingAdvice, as expected
  • third log: "three " + undefined

Thank you for you help!

3
problem with your invocation keyword? Does it match with your custom slot?Amod Gokhale
It does match the slot yes, this is not the issue.Constance G

3 Answers

0
votes

When you say "tested from AWS Lambda", I assume that you mean using the AWS console to send a JSON test message to the Lambda, then looking at the response JSON to determine if it is correct?

If so, make sure that it matches the JSON sent to/from the Alexa test page in the dev portal. Sounds like they might be different.

Also, make sure that you are linked to the correct ARN in the Alexa skill.

0
votes

The undefined is likely a variable scope issue in the code.

I noticed in your response that you don't have any sessionAttributes. Is your code setting or pulling the value for the response from a session value? If so, the values need to be sent back with the sessionAttributes.

0
votes

I figured out what was wrong, I needed to move the response code into the callback function, like this:

'DressingTodayIntent': function() {
    var speechOutput;
    var self = this;
    var dressingAdvice = getJSON('https://api.darksky.net/forecast/9e0495a835ed823a705a9a567eee982a/48.861317,2.348764?units=si!ude=currently,minutely,hourly,alerts,flags',
        function(err, forecast) {
            if (err) {
              console.log('Error occurred while trying to retrieve weather data', err);
            } else {
              speechOutput = getDressingAdvice(forecast, true);
            }
            self.response.cardRenderer("Your dressing advice for today:", speechOutput);
            self.response.speak(speechOutput);
            self.emit(':responseReady');
        });    
},