Class: RoboPigeon::Slack::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/robopigeon/slack/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



4
5
6
7
8
# File 'lib/robopigeon/slack/message.rb', line 4

def initialize
  self.attachments = []
  self.users = []
  self.channels = []
end

Instance Attribute Details

#attachmentsObject

Returns the value of attribute attachments.



3
4
5
# File 'lib/robopigeon/slack/message.rb', line 3

def attachments
  @attachments
end

#channelsObject

Returns the value of attribute channels.



3
4
5
# File 'lib/robopigeon/slack/message.rb', line 3

def channels
  @channels
end

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/robopigeon/slack/message.rb', line 3

def text
  @text
end

#usersObject

Returns the value of attribute users.



3
4
5
# File 'lib/robopigeon/slack/message.rb', line 3

def users
  @users
end

Instance Method Details

#clientObject



10
11
12
# File 'lib/robopigeon/slack/message.rb', line 10

def client
  RoboPigeon::Slack::Client
end

#send!Object



26
27
28
29
30
31
32
33
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# 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