Skip to content

Instantly share code, notes, and snippets.

@eurica
Created July 7, 2016 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eurica/a0889f8f0746841bda1d3aa1512b4730 to your computer and use it in GitHub Desktop.
Save eurica/a0889f8f0746841bda1d3aa1512b4730 to your computer and use it in GitHub Desktop.
A custom event transformer to create incidents from Cisco Spark
function transform(PD) {
var webhook = PD.inputRequest.body
var message = webhook.text || "Error: Not a Spark chat message";
var room_link = ciscospark2web(b64decode(webhook.roomId)); // clean up the link
var normalized_event = {
incident_key: room_link, //So that all messages from a room de_dupee into the same incident
event_type: PD.Trigger,
description: message,
details: {
email: webhook.personEmail
},
client: "Cisco Spark",
client_url: room_link
};
// If the message is "thanks" => automatically close the incident
if (message.toLowerCase() == "thanks") {
normalized_event.event_type = PD.Resolve;
}
// Create the PD event
PD.emitEvents([normalized_event])
}
// Helper functions:
function b64decode(b) {
return new Buffer(b || "", "base64").toString("utf8");
}
function ciscospark2web(url) {
// from: ciscospark://us/ROOM/31ce2d70-3f09-11e6-946f-11a974144a8d
// to: https://web.ciscospark.com/#/rooms/31ce2d70-3f09-11e6-946f-11a974144a8d
return url.replace("ciscospark://us/ROOM/", "https://web.ciscospark.com/#/rooms/")
// TODO: Links to 1-1 chats & direct to messages
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment