class RoboPigeon::Slack::Message

Attributes

attachments[RW]
channels[RW]
text[RW]
users[RW]

Public Class Methods

new() click to toggle source
# File lib/robopigeon/slack/message.rb, line 4
def initialize
  self.attachments = []
  self.users = []
  self.channels = []
end

Public Instance Methods

client() click to toggle source
# File lib/robopigeon/slack/message.rb, line 10
def client
  RoboPigeon::Slack::Client
end
send!() click to toggle source
# File lib/robopigeon/slack/message.rb, line 26
def send!
  users.reject(&:nil?).each do |user|
    send_message(user)
  end
  channels.reject(&:nil?).each do |channel|
    send_message(channel)
  end
end
send_message(recipient) click to toggle source
# File lib/robopigeon/slack/message.rb, line 14
def send_message(recipient)
  raise 'No text or attachments set' if (text.nil? || text.empty?) && attachments.empty?

  client.client.chat_postMessage(
    channel: recipient,
    text: text,
    icon_emoji: client.emoji,
    username: client.name,
    attachments: attachments
  )
end