Skip to content

Instantly share code, notes, and snippets.

@PatrickTulskie
Last active March 3, 2017 20:19
Show Gist options
  • Save PatrickTulskie/998b2d0cc6232cd1d13adf02c8ded1b6 to your computer and use it in GitHub Desktop.
Save PatrickTulskie/998b2d0cc6232cd1d13adf02c8ded1b6 to your computer and use it in GitHub Desktop.
VictorOps Handler for Lita
Lita.configure do |config|
# ...
config.handlers.victor_ops.api_id = "API_ID"
config.handlers.victor_ops.api_key = "API_KEY"
end
# Usage: ack __incident_number__ __victorops_username__
module Lita
module Handlers
class VictorOps < Handler
include LitaUtility
include HTTParty
route(/ack (\d+)\s(\w*)$/i, :ack)
base_uri 'https://api.victorops.com/api-public/v1/'
config :api_id
config :api_key
def ack(response)
parts = response.matches.flatten
incident = parts[0]
user = parts[1]
deliver_ack(user: user, incident: incident, message: "acked in chat via #{robot.name}")
response.reply("Acking #{incident} by #{user}")
end
private
def default_headers
@default_headers ||= {
'X-VO-Api-Id' => config.api_id,
'X-VO-Api-Key' => config.api_key,
'Content-Type' => 'application/json'
}
end
def deliver_ack(user: nil, incident: nil, message: nil)
data = {
'userName' => user,
'incidentNames' => [incident],
'message' => message
}
results = self.class.patch("/incidents/ack", body: data.to_json, headers: default_headers)
Lita.logger.info(results.inspect)
results
end
end
Lita.register_handler(VictorOps)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment