I have a module that includes a request call, which doesn't appear to be getting executed.
var request = require('request');
var Alexa = require('alexa-sdk');
var APP_ID = <my alexa app ID>;
var self = module.exports = {
handler : function (event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(self);
alexa.execute();
},
"TestIntent": function () {
var speechOutput = "Recorded Test";
request("http://www.google.com",
function(error, response,body)
{
return console.log(body);
}
);
this.emit(':tell', speechOutput);
}
}
I never see the google body show up in my console.log on Lambda console or anywhere else. I've tried other calls (like API posts to my application server API) and do not see that show up on that server either.
Seems like the process is closing before the request callback completes.
In the Amazon Lambda "tester" I get a valid response. In the Alexa "tester" I get back the response of "Recorded Test". And on the Echo (via Alexa), I get back "Recorded Test" response from the device. So the skill seems to be working great. It's just the "request" action (in this case, just pulling google.com) that is failing.
Thanks!!
UPDATE: I was at least able to get the call to complete, but probably not the cleanest way.
var request = require('request');
var Alexa = require('alexa-sdk');
var APP_ID = <my alexa app ID>;
var self = module.exports = {
handler : function (event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(self);
alexa.execute();
},
"TestIntent": function () {
var that = this;
var speechOutput = "Recorded Test";
request("http://www.google.com",
function(error, response,body)
{
console.log(body);
that.emit(':tell', speechOutput);
return;
}
);
}
}