Sha256: cfef2dffadab0cf52aa051f1ba6dc08f4fe166447678da8dbc88f796020d6fe8

Contents?: true

Size: 959 Bytes

Versions: 15

Compression:

Stored size: 959 Bytes

Contents

require 'slack-notifier'

class Eye::Notify::Slack < Eye::Notify

  # Eye.config do
  #   slack :webhook_url => "http://...", :channel => "#default", :username => "eye"
  #   contact :channel, :slack, "@channel"
  # end

  param :webhook_url, String, true
  param :channel,     String, nil, '#default'
  param :username,    String, nil, 'eye'

  param :icon, String

  def execute
    debug { "send slack #{[channel, username]} - #{[contact, message_body]}" }

    options = {
      channel:  channel,
      username: username
    }

    options[:icon_emoji] = icon if icon && icon.start_with?(':')
    options[:icon_url]   = icon if icon && icon.start_with?('http')

    notifier = ::Slack::Notifier.new webhook_url, options

    notifier.ping message_body
  end

  def message_body
    payload = ''
    payload << "#{contact}: *#{msg_host}* _#{msg_full_name}_ at #{Eye::Utils.human_time2(msg_at)}\n"
    payload << "> #{msg_message}"
    payload
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
eye-0.10.1.pre lib/eye/notify/slack.rb
eye-0.10.0 lib/eye/notify/slack.rb
eye-0.10.0.alpha2 lib/eye/notify/slack.rb
eye-0.10.0.alpha lib/eye/notify/slack.rb
eye-0.9.4.nosigar lib/eye/notify/slack.rb
eye-0.9.4 lib/eye/notify/slack.rb
eye-0.9.3 lib/eye/notify/slack.rb
eye-0.9.2.nosigar lib/eye/notify/slack.rb
eye-0.9.2 lib/eye/notify/slack.rb
eye-0.9.1 lib/eye/notify/slack.rb
eye-0.9.pre lib/eye/notify/slack.rb
eye-0.8.1 lib/eye/notify/slack.rb
eye-0.8.celluloid15 lib/eye/notify/slack.rb
eye-0.8 lib/eye/notify/slack.rb
eye-0.8.rc lib/eye/notify/slack.rb