Class: ExceptionNotifier::MattermostNotifier

Inherits:
BaseNotifier show all
Defined in:
lib/exception_notifier/mattermost_notifier.rb

Instance Attribute Summary

Attributes inherited from BaseNotifier

#base_options

Instance Method Summary collapse

Methods inherited from BaseNotifier

#_post_callback, #_pre_callback, #initialize, #send_notice

Constructor Details

This class inherits a constructor from ExceptionNotifier::BaseNotifier

Instance Method Details

#call(exception, opts = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/exception_notifier/mattermost_notifier.rb', line 7

def call(exception, opts = {})
  options = opts.merge(base_options)
  @exception = exception

  @formatter = Formatter.new(exception, options)

  @gitlab_url = options[:git_url]

  @env = options[:env] || {}

  payload = {
    text: message_text.compact.join("\n"),
    username: options[:username] || "Exception Notifier"
  }

  payload[:icon_url] = options[:avatar] if options[:avatar]
  payload[:channel] = options[:channel] if options[:channel]

  httparty_options = options.except(
    :avatar, :channel, :username, :git_url, :webhook_url,
    :env, :accumulated_errors_count, :app_name
  )

  httparty_options[:body] = payload.to_json
  httparty_options[:headers] ||= {}
  httparty_options[:headers]["Content-Type"] = "application/json"

  HTTParty.post(options[:webhook_url], httparty_options)
end