diff --git a/app/models/notification_services/slack_service.rb b/app/models/notification_services/slack_service.rb index abab9f7..3aa68ac 100644 --- a/app/models/notification_services/slack_service.rb +++ b/app/models/notification_services/slack_service.rb @@ -1,41 +1,27 @@ class NotificationServices::SlackService < NotificationService Label = "slack" Fields += [ - [:subdomain, { - :placeholder => 'subdomain', - :label => 'Subdomain portion for Slack service' - }], - [:api_token, { - :placeholder => 'Slack Integration Token', - :label => 'Token' - }], - [:room_id, { - :placeholder => '#general', - :label => 'Room where Slack should notify' + [:service_url, { + :placeholder => 'Slack Hook URL (https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX)', + :label => 'Hook URL' }] ] def check_params - if Fields.detect {|f| self[f[0]].blank? unless f[0] == :room_id } - errors.add :base, "You must specify your Slack subdomain and token." + if Fields.detect {|f| self[f[0]].blank? } + errors.add :base, "You must specify your Slack Hook url." end end - def url - "https://#{subdomain}.slack.com/services/hooks/incoming-webhook?token=#{api_token}" - end - def message_for_slack(problem) "[#{problem.app.name}][#{problem.environment}][#{problem.where}]: #{problem.error_class} #{problem_url(problem)}" end def post_payload(problem) - payload = {:text => message_for_slack(problem) } - payload[:channel] = room_id unless room_id.empty? - payload.to_json + {:text => message_for_slack(problem) }.to_json end def create_notification(problem) - HTTParty.post(url, :body => post_payload(problem), :headers => { 'Content-Type' => 'application/json' }) + HTTParty.post(service_url, :body => post_payload(problem), :headers => { 'Content-Type' => 'application/json' }) end end diff --git a/docs/notifications/slack/airbrake_notification.png b/docs/notifications/slack/airbrake_notification.png new file mode 100644 index 0000000..8c0c103 Binary files /dev/null and b/docs/notifications/slack/airbrake_notification.png differ diff --git a/docs/notifications/slack/errbit.png b/docs/notifications/slack/errbit.png new file mode 100644 index 0000000..b9857d1 Binary files /dev/null and b/docs/notifications/slack/errbit.png differ diff --git a/docs/notifications/slack/errbit_notification.png b/docs/notifications/slack/errbit_notification.png new file mode 100644 index 0000000..8824c3e Binary files /dev/null and b/docs/notifications/slack/errbit_notification.png differ diff --git a/docs/notifications/slack/hook_url.png b/docs/notifications/slack/hook_url.png new file mode 100644 index 0000000..89a76fc Binary files /dev/null and b/docs/notifications/slack/hook_url.png differ diff --git a/docs/notifications/slack/index.md b/docs/notifications/slack/index.md new file mode 100644 index 0000000..0b6aa22 --- /dev/null +++ b/docs/notifications/slack/index.md @@ -0,0 +1,24 @@ +# Slack + +The slack notification sends to [Slack](https://www.slack.com/). + +## Configuration + +### Add the Airbrake Notification Integration on Slack + +![Airbrake Notification](airbrake_notification.png) + +### Hook URL + +Copy the Hook URL specified by the Slack service. + +![Hook URL](hook_url.png) + +Optionally change the name of the integration to "Errbit", and include the errbit logo for inline messages: ![Errbit](errbit.png) + +### Setup in Errbit + +On the App Edit Page, click to highlight the slack integration. +Input the hook url from above into the field and click save. + +![Errbit Notification Setup](errbit_notification.png) \ No newline at end of file diff --git a/spec/fabricators/notification_service_fabricator.rb b/spec/fabricators/notification_service_fabricator.rb index 832672c..a32f9d2 100644 --- a/spec/fabricators/notification_service_fabricator.rb +++ b/spec/fabricators/notification_service_fabricator.rb @@ -12,6 +12,10 @@ Fabricator :gtalk_notification_service, :from => :notification_service, :class_n service { sequence :word } end -%w(campfire flowdock hipchat hoiio hubot pushover slack webhook).each do |t| +Fabricator :slack_notification_service, :from => :notification_service, :class_name => "NotificationService::SlackService" do + service_url { sequence :word } +end + +%w(campfire flowdock hipchat hoiio hubot pushover webhook).each do |t| Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" end diff --git a/spec/models/notification_service/slack_service_spec.rb b/spec/models/notification_service/slack_service_spec.rb index e512ae8..43d4bb9 100644 --- a/spec/models/notification_service/slack_service_spec.rb +++ b/spec/models/notification_service/slack_service_spec.rb @@ -1,26 +1,13 @@ describe NotificationService::SlackService, type: 'model' do - it "it should send a notification to Slack with channel" do + it "it should send a notification to Slack with hook url" do # setup notice = Fabricate :notice - notification_service = Fabricate :slack_notification_service, :app => notice.app - problem = notice.problem - - # faraday stubbing - payload = {:text => notification_service.message_for_slack(problem), :channel => notification_service.room_id}.to_json - expect(HTTParty).to receive(:post).with(notification_service.url, :body => payload, :headers => {"Content-Type" => "application/json"}).and_return(true) - - notification_service.create_notification(problem) - end - - it "it should send a notification to Slack without a channel" do - # setup - notice = Fabricate :notice - notification_service = Fabricate :slack_notification_service, :app => notice.app, :room_id => "" + notification_service = Fabricate :slack_notification_service, :app => notice.app, :service_url => "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX" problem = notice.problem # faraday stubbing payload = {:text => notification_service.message_for_slack(problem)}.to_json - expect(HTTParty).to receive(:post).with(notification_service.url, :body => payload, :headers => {"Content-Type" => "application/json"}).and_return(true) + expect(HTTParty).to receive(:post).with(notification_service.service_url, :body => payload, :headers => {"Content-Type" => "application/json"}).and_return(true) notification_service.create_notification(problem) end -- libgit2 0.21.2