I keep getting an issue with the following code with Amazon Lambda and the alexa skills kit. I have spent countless hours on this and cannot get it to work. I keep getting this message returned and can't figure out why the http get is failing. "Please try again later". It isn't even printing the console messages.
var Alexa = require('alexa-sdk');
var http = require('http');
var APP_ID = "omitted";
var SKILL_NAME = 'omitted';
var options = {
host: 'api.forismatic.com',
path: '/api/1.0/?method=getQuote&lang=en&format=text',
method: 'GET'
};
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'LaunchRequest': function () {
this.emit('Inspiration');
},
'IntentRequest': function() {
this.emit('Inspiration');
},
'InspirationIntent': function () {
this.emit('Inspiration');
},
'Inspiration': function () {
var speechOutput = '';
var text = '';
http.get(options, function(res) {
console.error("Got response: " + res.statusCode);
res.on("data", function(chunk) {
console.error("BODY: " + chunk);
text = chunk;
});
}).on('error', function(e) {
text = 'error' + e.message;
console.error("Got error: " + e.message);
});
if(text == ''){
speechOutput = "Please try again later";
}
else{speechOutput = text;}
this.emit(':tellWithCard', speechOutput, SKILL_NAME, text);
},
'AMAZON.HelpIntent': function () {
var speechOutput = "You can ask Inspirational Quote for some advice.";
var reprompt = "What would you like me to do?";
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', 'Goodbye!');
},
'AMAZON.StopIntent': function () {
this.emit(':tell', 'Goodbye!');
},
'Unhandled': function() {
this.emit('AMAZON.HelpIntent');
}
};