Class: Totalizer::SlackNotifier

Inherits:
BaseNotifier show all
Defined in:
lib/totalizer/notifier/slack_notifier.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{ username: 'Totalizer', icon_emoji: ":nerd_face:", color: '#5767ff' }

Class Method Summary collapse

Class Method Details

.call(message_groups, options) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/totalizer/notifier/slack_notifier.rb', line 7

def self.call(message_groups, options)
  notifier = Slack::Notifier.new options[:webhook_url], DEFAULT_OPTIONS.merge(options)
  message_groups.each do |message_type, messages|
    text = messages.map{ |message| message.text }.join("\n")
    description = messages.map{ |message| message.description }.uniq.join("\n")
    notifier.ping message_type.to_s.capitalize, attachments: [{ fallback: text, color: options[:color], text: text, footer: description }]
  end
end