RSS Push Notifications using Parse

Recently we have moved our apps to Parse and one thing we wanted to do is to send RSS Push Notifications. This way we can notify using Push Notifications every time we publish a post in our blog.

Searching on Google we have found that a lot of people asked for this, and there was no published solution. We have developed a solution for doing this using Cloud Code, and we want to share it with you.

Set up Cloud Code on your machine

To set up Cloud Code is very easy. Just run this line in your terminal and Cloud Code will be installed:

curl -s | sudo /bin/bash

If you are a Windows user you can follow Parse Documentation instructions:

The Parse command line tool for Windows is available here. After downloading the zip file and unzipping it, you can launch a parse-aware powershell session by double clicking ParseConsole.exe. After the first run of the ParseConsole, you can also start the powershell session by hitting Win + R and typing “parse”

Get Feed Item from RSS Feed with Parse Cloud Code

You will need two libraries on your Cloud Code in order to parse XML feed. This libraries are sax-js and xmlreader. You just simple download this js files to your Cloud folder, and change the following line on xmlreader.js: var sax = require(“sax”) to var sax = require(“cloud/sax”).

In your main.js file you can now use the parser using this variable xmlreader:

Use database to check if push was already sent

We create a function to save a Post on our database. This way the next time we run the job we can see if it’s already sent for a particular blog post.

Now, we try to find if the post is already sent and if not, we save it.

Send RSS Push Notifications to all installations

This example works for sending a push to everyone, buy you can customize it to send it to specific channels following the JS reference of Parse.

Make a job to perform this task every 15 minutes

Now you should encapsulate the code inside a job, and configure it to send it every 15 minutes on the parse dashboard website.

RSS Push Notifications using Parse: Scheduled Jobs

RSS Push Notifications using Parse: Scheduled Jobs

All code together

This is all the code to send push using a RSS Feed using Parse.

  • B.

    October 16, 2015 at 6:53 am Reply

    I always get the following error in the Terminal when I want upload the code:
    Error: Uncaught SyntaxError: Unexpected token ILLEGAL in xmlreader.js:25
    at main.js:1:17
    Has somebody got a solution?

  • Marcus

    January 2, 2016 at 4:36 pm Reply

    Why i get this error in parse when i try to push notifications?:
    TypeError: Cannot read property ‘entry’ of undefined
    at main.js:38:27
    at Object.saxparser.onend (xmlreader.js:104:10)
    at emit (sax.js:639:35)
    at end (sax.js:682:5)
    at Object.write (sax.js:981:14)
    at Object.SAXParser.close (sax.js:156:38)
    at (xmlreader.js:157:29)
    at Object.Parse.Cloud.httpRequest.success (main.js:37:14)
    at Object. (:844:19)

    please help me!

Post a Comment