Sometimes email is the wrong choice for webapp notifications.  Our inboxes are becoming increasingly cluttered, and especially for those of us who carry PDAs, it can be a pain to scroll through twelve facebook notifications just to get to the mail that we actually need to read.  What's more, email just isn't that great of a tool for receiving short messages, since you have to open them each individually.  At the very least, it's nice to have another choice. 

Particularly with shorter notifications, instant messaging can be a great alternative to email.  The messages don't clutter up your inbox, or need to be opened individually.  Most people already use it on a daily basis.  The only problem is implementation. 

ActionMessager

ActionMessager is a simple framework for creating IM-based notifiers.  It is structured like ActionMailer, so it's got virtually zero learning curve for most rails developers.  What's more, because the syntax is the same, it's pretty easy to create a delegate class that acts like your mailer, but sends IMs as well.  That means drop-in replacement! 

All you have to do start sending IM notifications to your users is subclass ActionMessager::Base.  Then, create a method that sets an array of recipients, and returns the message you'd like to send:

class JabberNotifier<ActionMessager::Basedef friendship_request(friendship_request)@recipients=friendship_request.receiver.jabber_contact"You have received a friendship request from #{friendship_request.sender.name}!  Click here to accept or decline: #{friendship_request.url}"endend

Then, wherever you'd like to send the notification:

JabberNotifier.deliver_friendship_request(friendship_request)

That's all there is to it. 

Caveats

Currently, only jabber is supported.  It is possible to access other IM services over jabber, but I'm not 100% clear how it works, and I don't yet have need for it, so that may or may not come later. 

The bigger caveat, though, is speed.  Sending a notification takes anywhere from 1-2s (whether you send 1 or 5).  It may be possible to improve performance by using a different jabber library, and I'll probably investigate that in the near future.  Even with a performance boost, though, you should still take your notifications out of the request cycle, by using something like workling to process them asynchronously.