mod_zeropush and eJabberd for offline Push Notifications
Published 2013-10-23 by Stefan Natchev

Introducing mod_zeropush

mod_zeropush is an eJabberd module for sending Push Notifications to offline users.

If you're building a mobile app that has a chat component, you probably want to separate as much of that functionality away from your back-end application as possible. eJabberd is great stand-alone XMPP server with robust messaging and presence features. It is widely touted as being able to handle enormous amounts of concurrent messaging and is praised for it's stability.

A common feature with mobile chat apps is sending push notifications to users who receive a message while they are offline. eJabberd does not have that functionality built in, but it is quite extensible. mod_zeropush takes advantage of the extensibility to add this common feature without having to store device tokens in your application.

If you want to have control over the content of the Push Notification from within your web app, check out mod_interact and our previous blog post: iOS Push Notifications from eJabberd

How it works

Recently, we introduced broadcast channels to the ZeroPush API. Using this feature, you can create a broadcast channel for every jabber id in your system. When a user needs to receive a message, you can simply broadcast the message to the channel and all of the devices associated with that jabber user will receive the notification.

Setting this up requires some code and configuration in both your iOS app and on your chat server.

In your iOS app

All that is required in the iOS app, is to subscribe to the broadcast channel as soon as your app has the desired jabber id. If you are using the ZeroPush Cocoapod you can subscribe to the channel as part of your the push notification registration callback.

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)tokenData
{
    [[ZeroPush shared] registerDeviceToken:tokenData];
    [[ZeroPush shared] subscribeToChannel:@"{jabberId}"];
    ...
}

If you do not use the cocoapod, refer to the register and subscribe endpoints.

Server-Side

Install by copying mod_zeropush.beam in the ebin directory of your eJabberd installation. The source is available on github.

Depending on the version of eJabberd you are running the configuration is slightly different. Version 2.1.x uses erlang syntax, found in /etc/ejabberd/ejabberd.cfg

{mod_zeropush, [
    {sound, "default"},
    {auth_token, "server-auth-token"},
    {post_url, "https://api.zeropush.com/broadcast"}
]}

Starting with version 13.10, the config files moved to yaml format.

mod_zeropush:
    sound: "default"
    auth_token: "server-auth-token"
    post_url: "https://api.zeropush.com/broadcast"

Downloads

Source can be found on github.