Twilio Hackpack + Pagerduty = Awesome

I just got back from the Twilio Signal Conference and all participants got the Hackpack v.3. It features a 3G enabled Particle Electron along with a 4×4 WS2812B RGB LED Matrix and a 2000mAh LiPo battery.

I been thinking how to actually use it for something useful and came up with the idea to use it as a visual monitoring display for my Pagerduty alarms. Two hours later it works!

It goes red when an Pagerduty incident is triggered, yellow if the incident is acknowledged and of course green when the incident was resolved.

Also I been playing around with the freshly introduced Twilio Functions (which are basically AWS Lambda functions) and use it as a proxy between the Pagerduty webhook and the 3G enabled Hackpack.

As a bonus I added multiple device support so multiple Hackpack’s can be notified at the same time.

var callbackTrigger = function(completed, max, callback, msg) {

    if(completed >= max) {
      callback(null, msg)
    }
}

exports.handler = function(context, event, callback) {

  var _ = require('lodash');

  // parse pagerduty
  if(_.isArray(event.messages)) {

    let incidentType = event.messages[0].type;
    let client = context.getTwilioClient();
    let sims = [/** List of SIM SID's */];
    let completed = 0;

    sims.forEach(function(sim, index) {

      client.preview.wireless.commands.create({
          command: incidentType,
          sim: sim
      }).then(function(response) {

            completed++;

            callbackTrigger(completed, sims.length, callback, 'triggered ' + incidentType);
      });

    });

    return;

  }

  return callback('Error: No incident type found', false);

};

};

Check out the full code on my GitHub.

[flyandi_button link=”https://github.com/flyandi/hackpackv3-pagerduty”]View on GitHub[/flyandi_button]