For some reason it seems like it does not execute http.get To check if ANY of the events were called, I made it return value from every call and it still returns "No Data" I am sure its something silly.
Hope you can help
Below is my code
'use strict';
var Alexa = require('alexa-sdk');
var APP_ID = "amzn1.ask.skill."; // TODO replace with your app ID (OPTIONAL).
var languageStrings = {
"en": {
"translation": {
"FACTS": [
"A year on Mercury is just 88 days long.",
"The temperature inside the Sun can reach 15 million degrees Celsius.",
"The Moon is moving approximately 3.8 cm away from our planet every year."
],
"SKILL_NAME": "Space Facts",
"GET_FACT_MESSAGE": "Here's your fact: ",
"HELP_MESSAGE": "You can say tell me a space fact, or, you can say exit... What can I help you with?",
"HELP_REPROMPT": "What can I help you with?",
"STOP_MESSAGE": "Goodbye!"
}
}
};
exports.handler = function (event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
// To enable string internationalization (i18n) features, set a resources object.
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'WhoAmIIntent': function () {
try {
console.log("WhoAmIIntent Called");
console.log(this.event.session.user.userId);
var Outcome = MyWhoAmIIntent(this.event.session.user.userId);
this.emit(':tell', Outcome);
} catch (e) {
this.emit(':tell', e);
}
},
'AMAZON.HelpIntent': function () {
var speechOutput = this.t("HELP_MESSAGE");
var reprompt = this.t("HELP_MESSAGE");
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', this.t("STOP_MESSAGE"));
},
'AMAZON.StopIntent': function () {
this.emit(':tell', this.t("STOP_MESSAGE"));
}
};
function MyWhoAmIIntent(DeviceToken) {
console.log("MyWhoAmIIntent Function Called");
var http = require('http');
if (http == null) {
console.log("HTTP NULL");
} else {
console.log("HTTP Created");
}
http.get("http://api.ipify.org?format=json", function (res) {
var body = '';
res.on('data', function (data) {
body += data;
console.log(data);
return "datga";
});
res.on('end', function () {
var parsed = JSON.parse(body);
console.log(parsed);
return "Done- ENd";
});
})
.on('error', function (e) {
console.log("Got error: " + e.message);
return "Error";
});
return "No Data";
}
It returns "No Data" every time
via ullfindsmit
No comments:
Post a Comment