Photo from Chile

Send Push Notifications to an iPhone from ColdFusion

Notifo is a relatively new service which allows you to send push notifications to mobile clients via a REST interface. Currently notifications can only be sent to the iPhone, but they plan to add support for Android and Blackberry in the future. Because it is based on a REST API, it's very easy to interact with from a ColdFusion application, and I wanted to give it a try, so I whipped up a quick API wrapper for it. It all seems to work extraordinarily well, and is quite cool.

CFNotifo is Born

I found out about Notifo from the GitHub blog, which describes a Notifo service hook that was just added. This service hook allows you to receive push notifications on your iPhone any time someone commits to your Git repo. Of course I had to try this right away, and was duly impressed. The next step was to write some CFML that interacts with the API, so, as I mentioned above, I decided to create a simple API wrapper to make it even easier for others to do the same. In a matter of minutes I was able to create a single cfc which implements all of the current API. This wasn't that challenging as there are only two API methods right now, subscribe_user and send_notification, but as Notifo adds more, I will follow suit.

How Does Notifo Work

Paul Stamatiou, co-founder of Notifo, wrote up a detailed post about Notifo on his blog, which is well worth reading. If you don't feel like following the link, here are the highlights:

  • Allows you to send push notifications to a mobile client from a server.
  • Currently iPhone is supported, via an app available in the app store. Android is up next, with other smartphones to be added in the future.
  • To subscribe to services you need a Notifo account, which can be set up via the Notifo site, or via the iPhone app.
  • To receive notifications you need to have the iPhone app installed.
  • Once you've subscribed to a service you can set various options for it via a web interface, including what type of notifications you want to receive (normal, silent and stealth), and you can unsubscribe, block and report spam on a service.
  • You can also set some global options for notifications, such as silent hours, during which notifications will be sent silently.

How to Use CFNotifo

The API wrapper that I wrote is extremely simple to use. You just instantiate an object, passing in the credentials for your service, and then call the subscribe and/or send methods on that object. Here are a couple of examples:

view plain print about
1// Subscribe a user to a service
2CFNotifo = createObject("component","CFNotifo").init(username="serviceNotifoUsername",apiSecret="serviceAPISecret");
3response = CFNotifo.subscribe(username="userToSubscribe");
4if (response.success)
5{
6    // It worked!
7} else
8{
9    // Something went wrong
10    writeDump(var=response.notifoResponse, label="Notifo's Response");
11}
12
13// Send a notification
14CFNotifo = createObject("component","CFNotifo").init(username="serviceNotifoUsername",apiSecret="serviceAPISecret");
15response = CFNotifo.send(to="subscribedUser", msg="Message to send");
16if (response.success)
17{
18    // It worked!
19} else
20{
21    // Something went wrong
22    writeDump(var=response.notifoResponse, label="Notifo's Response");
23}

A Working Demo

If you want to see CFNotifo in action, you can visit my CFNotifo demo page. This will allow you to subscribe to a service that I created using CFNotifo. As mentioned above, you'll need a Notifo account to be able to subscribe, and the iPhone app to receive mobile notifications (you can also see all of your notifications via Notifo's web interface if you don't have an iPhone or don't want to install the app). Once everything is in place, you'll receive a push notification whenever I add a new post to my blog.

As I was writing up this post I realized that the demo I just described isn't that useful as a demo as you won't see any actual notifications until I post a new article, so I've added a new demo service that you can use to force a notification to be sent. Simply use demo 2 to subscribe to the Test Service, and then use the next form to send yourself a notification.

What's Next?

The complete Notifo API has been implemented in CFNotifo, but Notifo also offers Webhooks, which allow you to configure a URL to be hit whenever a notification is sent to your account. I plan to add support for creating your own webhooks to the next version of CFNotifo.

CFNotifo is hosted on GitHub and RIAForge, from whence you can download the code. I'm also very pleased that CFNotifo has been included in the official repo for Notifo APIs on GitHub. If you have any questions or suggestions you can comment on this post, and any issues you encounter can be added to the issue tracker at GitHub.

TweetBacks
Comments
I got excited until I got to the part about having to have an account with Notifo, and their iPhone app.

I learned more about mobile apps at this weekend's D2WC conference. One of the things we talked about was a new service by a company called Urban Airship:

http://urbanairship.com/products/push/
# Posted By andy matthews | 6/21/10 9:51 AM
I don't think there's a silver bullet, Andy. I believe the point of Notifo is that you don't need to do any mobile app development. It's not about adding a feature to a mobile app, it's about enabling notifications from outside a mobile app. So I, as a web developer, don't need to know anything about mobile development, and I can still create something that can send notifications to a phone.

I could easily be wrong about this, but it seems to me that the only way you're going to be able to get notifications onto a phone is via an app - either one that you write yourself, or something like Notifo that enables you to interact with it. Would you say that's accurate?

Urban Airship does sound like an interesting service, but I think it fulfills a different need than Notifo.
# Posted By Bob Silverberg | 6/21/10 10:09 AM
Thanks for the write-up and developing CFNotifo Bob!
# Posted By Paul Stamatiou | 6/21/10 4:26 PM
check out Xtify -

xtify uses an SDK for easy implementation and has a web console and web service to configure messages to one, some or all of your users. works across android, iphone and blackberry.

you can create rules that determine when a message gets sent – you can even push notifications using location as the trigger as the SDK runs in the background and provides access to persistent location.

reach out with questions to [email protected]
# Posted By Josh Schiffman | 6/23/10 2:36 PM
This sounds pretty cool. I don't mind so much the idea of having to have an App installed on the phone as I am not sure I could even contemplate how else it could be done (outside SMS). Even looking at that Urban Airship thing, it looks like it needs an App installed to work as well.
# Posted By Ben Nadel | 6/30/10 8:03 PM