Xervo

Modulus Notifications on the Pebble Smartwatch

Modulus Notifications on the Pebble Smartwatch

When your app is in production, you want to be notified when the status of your application changes. For example, when your application crashes you want to know immediately. You also have, or want to have, a Pebble smartwatch which allows you to view your notifications on your wrist, relinquishing the need to pick up your phone. With Modulus, we can combine Modulus' web hooks and Pushover, a notification app. When things about your application change you get a push notification which appears on your Pebble.

null

Modulus Notifications

Modulus supports web hooks. So, when a special event happens, like an application crash or deployment, we can set a url for the Modulus platform to POST to. To learn more about Modulus notifications check out the documentation.

Why Push Notifications?

Modulus already supports email notifications for the platform. Also, email notifications already come to the Pebble watch. So, one may think it would be useless to use a service like Pushover to deliver notifications specifically for the pebble. However, there are several advantages to using an app like Pushover, and using the Pebble watch just makes things convenient.

Emails notifications can crowd up inbox

If you receive a lot of emails, you could lose an important message in a sea of emails. It happens to all of us. Also, it's a good idea to not have these short time sensitive notifications contribute to that sea.

Customize sound

With an app like Pushover, you can customize the sound of the notifications you push to your phone. This can become helpful when you want unique sounds for specific things or a special sound for emergencies.

Integrate into other parts of your application

Pushover has an awesome API. This means that you can integrate Pushover into other parts of your application. You can integrate the API into your application to notify yourself of application specific events.

Setting Up Pushover

Pushover is an app you can download from the iOS or Play store for $4.99. That is a small price to pay to make sure that the service you provide is always available for your customers. After you purchase the app, create your account and obtain your user token. After you obtain a user token, fill out the form to register for an API token.

Sending the Notification

In order to send the notification, we are going to create an app that receives a POST request then it pushes the notification to your phone.

I created a very simple express app. The full example is here.

Modulus includes data about the application that fired the POST request in the body of the request.

// Modulus will include an object in the POST request
// Grab the type of action
var type = req.body.type;
// Grab the project details
var project = req.body.project;

var messageAction;
// Pushover has priorty settings.
// Learn more here: https://pushover.net/api#priority
var priority = 0;

// Grab current time
var time = moment().format("dddd, MMMM Do YYYY, h:mm:ss a");

// We want the message to be different depending on the type
switch(type){
case "start":
 messageAction = " has been started.";
 break;
case "stop":
 messageAction = " has stopped.";
 break;
case "restart":
 messageAction = " has been restarted.";
 break;
case "deploy":
 messageAction = " has been deployed.";
 break;
case "scale":
 messageAction = " has scaled.";
 break;
case "crash":
 messageAction = " has crashed.";
 priority = 2;
 break;
default:
 return res.send(400, "Type not found");
}

Then we want to create a Pushover object and send it.

// Create a Pushover object with the user, token, and priority
var p = new push( {
    user: user,
    token: TOKEN,
    priority: priority
});

// Create our message and title
var msg = {
    title: project.name + messageAction,
    message: "Project name : " + project.name
            + "\n\n" + "Time of " + type + ": " + time + "\n\n"
            + "Project URL : " + project.domain + "\n\n"
            + "Log on to modulus for more details\n"
};

// Send to phone
p.send( msg, function( err, result ) {

if ( err ) {
        throw err;
    }

});

You can pull the modulus-pushover project from GitHub, add your Api Token, then deploy your instance of the modulus-pushover application to Modulus. After you deploy, go to another project's page and click notifications. There you will be able to add the webhook POST url and specify what notifications you want. In the url, add your user id like so:

http://moduluspush.onmodulus.net?user=xxxxxxxxxxxxxxxxxxxxxxxxxxx 

Now, when your application crashes, deploys, restarts, etc. you will get a push notification, which will appear on your Pebble Smartwatch. Enjoy!

What is Xervo?

Xervo makes deploying applications in the public cloud or your own data center easy. Node.js, PHP, Java, Python, Nginx, and MongoDB supported. Full Docker support included in Enterprise version. It’s free to get started.

Share This Article

comments powered by Disqus