I can't seem to get HTTP requests to work in my alexa skill, here is the relevant sample code:
var https = require('https');
...
function getTreeFact(callbackFunction){
var url = 'https://alexa.phl.chs.network/treefacts/index.php';
https.get(url, function(res){
var body = '';
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
var gameResponse = JSON.parse(body);
callbackFunction(gameResponse);
});
}).on('error', function(e){
// Handle error
});
}
...
this.getTreeFact(function (responseMessage){
this.emit(':tell', responseMessage.message);
});
I have no idea what I am doing wrong, I think I am making the HTTP request correctly. I know the skill works without this (simply commenting out the last three lines and replacing with just this.emit(':tell', 'hello') works fine).