Skip to content

Instantly share code, notes, and snippets.

@ijason
Created April 22, 2017 23:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ijason/5eeb42f4e8004bbd8ab3d6f10f14c502 to your computer and use it in GitHub Desktop.
Save ijason/5eeb42f4e8004bbd8ab3d6f10f14c502 to your computer and use it in GitHub Desktop.
'use strict';
var Alexa = require('alexa-sdk');
var APP_ID = "YOUR_APP_ID"; // TODO replace with your app ID (OPTIONAL).
var https = require('https');
var optionsget = {
host : 'query.yahooapis.com',
port : 443,
path : '/v1/public/yql?q=YOUR_RSS_QUERY&format=json&diagnostics=true&callback=', // TODO replace with your YQL json URL
method : 'GET'
};
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 = {
'LaunchRequest': function () {
var reprompt = "What can I help you with?";
this.emit(':ask', reprompt, reprompt);
},
'GetNewFactIntent': function () {
this.emit('GetFact');
},
'GetFact': function () {
var t = this;
getWod(function (events) {
if (events.length == 0) {
var speechOutput = "There was a problem retrieving the wod. Please try again later.";
t.emit(':tell', speechOutput);
} else {
// Create speech output
var speechOutput = events;
var cardTitle = "Ballistic Crossfit Unofficial";
t.emit(':tellWithCard', speechOutput, cardTitle, speechOutput);
}
});
},
'AMAZON.HelpIntent': function () {
var speechOutput = "You can say, tell me the wod, or, you can say cancel... What can I help you with?";
var reprompt = "What can I help you with?";
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
var speechOutput = "Goodbye";
this.emit(':tell', speechOutput);
},
'AMAZON.StopIntent': function () {
var speechOutput = "Goodbye";
this.emit(':tell', speechOutput);
}
};
function getWod(eventCallback) {
var reqGet = https.request(optionsget, function(res) {
var finalData = "";
res.on('data', function(d) {
finalData += d.toString();
});
res.on("end", function() {
var obj = JSON.parse(finalData);
eventCallback(obj);
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.log("Got error: ", e);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment