Class: Jackal::Slack::Notification

Inherits:
Callback
  • Object
show all
Defined in:
lib/jackal-slack/notification.rb

Instance Method Summary collapse

Instance Method Details

#execute(message) ⇒ Object



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

def execute(message)
  failure_wrap(message) do |payload|
    payload[:data][:slack][:messages].each do |slack_msg|
      notifier = slack_notifier
      msg = slack_msg[:message].to_s
      msg_attachment = {
        fallback: msg,
        text: msg,
        color: slack_msg[:color],
        mrkdwn_in: slack_msg.fetch(:markdown, true) ? [:text, :fallback] : []
      }
      notifier.ping(
        slack_msg.fetch(:description, 'Result:'),
        attachments: [msg_attachment]
      )
    end
    job_completed(:slack_notification, payload, message)
  end
end

#setup(*_) ⇒ Object



7
8
9
# File 'lib/jackal-slack/notification.rb', line 7

def setup(*_)
  require 'slack-notifier'
end

#slack_notifierObject

Return slack_notifier object using team & token from data or config depending on what’s loaded in the environment



43
44
45
# File 'lib/jackal-slack/notification.rb', line 43

def slack_notifier
  ::Slack::Notifier.new(config[:webhook_url])
end

#valid?(message) ⇒ Truthy, Falsey

Validity of message

Parameters:

  • message (Carnivore::Message)

Returns:

  • (Truthy, Falsey)


15
16
17
18
19
# File 'lib/jackal-slack/notification.rb', line 15

def valid?(message)
  super do |payload|
    payload.get(:data, :slack)
  end
end