My First Amazon Alexa Skill: Reading RSS using Node.js

I recently had my first Amazon Alexa skill published and am eagerly awaiting my Alexa Dev hoodie! Developing and publishing an Alexa skill is a lot easier than you might think especially with all the tutorials and resources Amazon provides. I decided to develop a skill that’ll read the WOD (Workout of the day) from the crossfit gym I go to. The only problem is that my gym’s website didn’t have a public API even though it was running on WordPress. Fortunately it did have an unpublished RSS feed that I was able to find the URL to.
I chose to create my skill using Node.js without having to use any node modules. This was a challenge since I couldn’t read in the RSS feed directly without running into any cross-domain issues. To overcome this I used Yahoo’s YQL to read the RSS feed and return the results via JSON. YQL can read any RSS feed using it’s SQL-like syntax.

select * from rss where url = 'RSS URL'

It even provides you with a REST url. Once I had that, the rest was easy.

var https = require('https');

var optionsget = {
    host : 'query.yahooapis.com', 
    port : 443,
    path : '/v1/public/yql?q=rssurl&format=json&diagnostics=true&callback=', // the rest of the url with parameters if needed
    method : 'GET' 
};

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);
    });
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Please Do the Math      
 

*