Create Incidents from SMS and display them on a wallboard

transformers
rest-api
summit18

(David Hayes) #1

This is a demo that we’re showing at Summit18:

I used 2 parts of the API, a Custom Event Transformer and ourREST API for Incidents.

The Custom Event Transformer is pretty easy, take the JSON that we get from Twilio, and if there’s a picture, send it along as a context.

var contexts = [];

if (PD.inputRequest.body.MediaUrl0) {
  contexts.push({
    "type": "image",
    "src": PD.inputRequest.body.MediaUrl0
  });
  PD.inputRequest.body.Body = "Picture"
}

var normalized_event = {
  incident_key: PD.inputRequest.body.SmsMessageSid,
  event_type: PD.Trigger,
  description: "SMS received: " + PD.inputRequest.body.Body,
  contexts: contexts
};

PD.emitGenericEvents([normalized_event]);

The page that displays the images & texts is a little sloppier (this is just a demo!). You can fork my demo code on jsfiddle: https://jsfiddle.net/eurica/zwyeatL1/ (don’t forget to change the service_ids)

$.ajax({
  dataType: "json",
  url: "https://api.pagerduty.com/incidents?statuses%5B%5D=triggered" +
    "&statuses%5B%5D=acknowledged&" +
    "service_ids%5B%5D=PK01EFR" +
    "&time_zone=UTC" +
    "&include%5B%5D=first_trigger_log_entries" +
    "&sort_by=created_at",
  headers: {
    "Accept": "application/vnd.pagerduty+json;version=2",
    "Authorization": "Token token=u9M7RTpKMPNAbb8yEyYu"
  },
  success: function(data) {
    //Update the screen
  }
});

(Simon Fiddaman) #2

Sounds like a good use case for paging InfoSec teams, etc. where you want a quick method that the rest of the business can use that doesn’t have to go via eg Slack.


(system) #3