Class: HasHelpers::SlackNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/has_helpers/utils/slack_notifier.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.default_channel_resolverObject

Returns the value of attribute default_channel_resolver.



13
14
15
# File 'lib/has_helpers/utils/slack_notifier.rb', line 13

def default_channel_resolver
  @default_channel_resolver
end

Class Method Details

.default_channelObject



16
17
18
19
# File 'lib/has_helpers/utils/slack_notifier.rb', line 16

def self.default_channel
  return nil if ::HasUtils::Env.test? || ::HasUtils::Env.development?
  default_channel_resolver&.call
end

.notify(message, channel: default_channel) ⇒ Object

CLASS METHODS ######



7
8
9
10
# File 'lib/has_helpers/utils/slack_notifier.rb', line 7

def self.notify(message, channel: default_channel)
  @default_notifier ||= HasHelpers::SlackNotifier.new
  @default_notifier.notify(message, channel: channel)
end

Instance Method Details

#notify(message, channel:) ⇒ Object

INSTANCE METHODS ######



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/has_helpers/utils/slack_notifier.rb', line 23

def notify(message, channel:)
  if channel.nil?
    puts message
    return
  end

  begin
    slack_client.chat_postMessage(channel: channel, text: message, as_user: true, mrkdwn: true, link_names: true)
  rescue => e
    ::Rails.logger.warn("Unable to send slack notification: #{e.message}")
  end
end