Skip to content

Commit

Permalink
MS Teams integration
Browse files Browse the repository at this point in the history
  • Loading branch information
iraklisk committed Jul 16, 2020
1 parent beacc63 commit 846b582
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
Binary file added app/assets/images/teams_create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/teams_goto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/teams_inactive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions app/models/notification_services/teams_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# coding: utf-8
class NotificationServices::TeamsService < NotificationService
LABEL = "teams"
FIELDS = [
[:api_token, {
placeholder: 'URL to receive a POST request when an error occurs',
label: 'URL'
}]
]

def check_params
if FIELDS.detect { |f| self[f[0]].blank? }
errors.add :base, 'You must specify the URL'
end
end

def create_notification(problem)
HTTParty.post(api_token, headers: { 'Content-Type' => 'application/json' }, body: post_payload(problem).to_json)
end

private

def post_payload(problem)
{
"summary" => post_payload_title(problem),
"themeColor" => "0078D7",
"title" => post_payload_title(problem),
"sections" => [
{
"activityTitle" => problem.message,
"facts" => post_payload_facts(problem)
}
],
"potentialAction" => post_payload_actions(problem)
}
end

def post_payload_title(problem)
error_title = problem.error_class || problem.message
"[#{problem.app.name}] #{error_title}"
end

def post_payload_facts(problem)
[
fact("Application:", problem.app.name),
fact("Environment:", problem.environment),
fact("Where:", problem.where),
fact("Times Occurred:", problem.notices_count.try(:to_s)),
fact(
"First Noticed:",
problem.first_notice_at.try(:localtime).try(:to_s, :db)
)
]
end

def fact(name, value)
{
"name" => name,
"value" => value
}
end

def post_payload_actions(problem)
[
{
"@type" => "OpenUri",
"name" => "View in Errbit",
"targets" => [
{
"os" => "default",
"uri" => problem.url
}
]
}
]
end
end
2 changes: 1 addition & 1 deletion spec/fabricators/notification_service_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
service { 'v2' }
end

%w(campfire flowdock hoiio hubot pushover webhook).each do |t|
%w(campfire flowdock hoiio hubot pushover teams webhook).each do |t|
Fabricator "#{t}_notification_service".to_sym, from: :notification_service, class_name: "NotificationServices::#{t.camelcase}Service"
end

0 comments on commit 846b582

Please sign in to comment.