Class: Webhookdb::Slack

Inherits:
Object
  • Object
show all
Extended by:
MethodUtilities
Includes:
Appydays::Configurable
Defined in:
lib/webhookdb/slack.rb

Defined Under Namespace

Classes: NoOpHttpClient

Class Method Summary collapse

Methods included from MethodUtilities

attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader

Class Method Details

.ignore_channel_not_foundObject



40
41
42
43
44
45
46
# File 'lib/webhookdb/slack.rb', line 40

def self.ignore_channel_not_found
  yield()
rescue ::Slack::Notifier::APIError => e
  return if e.message.include?("channel_not_found")
  return if e.message.include?("channel_is_archived")
  raise e
end

.new_notifier(opts = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/webhookdb/slack.rb', line 22

def self.new_notifier(opts={})
  opts[:channel] ||= "#eng-naboo"
  opts[:username] ||= "Unknown"
  opts[:icon_emoji] ||= ":question:"
  opts[:channel] = self.channel_override if self.channel_override
  if (force_chan = opts.delete(:force_channel))
    opts[:channel] = force_chan
  end
  return ::Slack::Notifier.new(self.webhook_url) do
    defaults opts
    if Webhookdb::Slack.suppress_all
      http_client NoOpHttpClient.new
    elsif Webhookdb::Slack.http_client
      http_client Webhookdb::Slack.http_client
    end
  end
end

.post_many(channels, notifier_options: {}, payload: {}) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/webhookdb/slack.rb', line 48

def self.post_many(channels, notifier_options: {}, payload: {})
  channels.each do |chan|
    notifier = self.new_notifier(notifier_options.merge(channel: chan))
    self.ignore_channel_not_found do
      notifier.post(payload)
    end
  end
end