lib/backup/notifier/slack.rb in backup_zh-4.0.3.1 vs lib/backup/notifier/slack.rb in backup_zh-4.2.0

- old
+ new

@@ -5,18 +5,14 @@ module Backup module Notifier class Slack < Base ## - # The Team name - attr_accessor :team + # The incoming webhook url + attr_accessor :webhook_url ## - # The Integration Token - attr_accessor :token - - ## # The channel to send messages to attr_accessor :channel ## # The username to display along with the notification @@ -63,25 +59,19 @@ # `:failure` # : The backup operation failed. # : Notification will be sent if `on_warning` or `on_success` is `true`. # def notify!(status) - tag = case status - when :success then '[Backup::Success]' - when :failure then '[Backup::Failure]' - when :warning then '[Backup::Warning]' - end - message = "#{ tag } #{ model.label } (#{ model.trigger })" - - data = { :text => message } + data = { + :text => message.call(model, :status => status_data_for(status)), + :attachments => [attachment(status)] + } [:channel, :username, :icon_emoji].each do |param| val = send(param) data.merge!(param => val) if val end - data.merge!(:attachments => [attachment(status)]) - options = { :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, :body => URI.encode_www_form(:payload => JSON.dump(data)) } options.merge!(:expects => 200) # raise error if unsuccessful @@ -149,10 +139,10 @@ when :warning then 'Backup Completed Successfully (with Warnings)!' end end def uri - @uri ||= "https://#{team}.slack.com/services/hooks/incoming-webhook?token=#{token}" + @uri ||= webhook_url end end end end