Class: Slackbotsy::Message

Inherits:
Hash
  • Object
show all
Includes:
Helper
Defined in:
lib/slackbotsy/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(caller, msg) ⇒ Message

convert message from a Hash obj to a Message obj



7
8
9
10
11
12
# File 'lib/slackbotsy/message.rb', line 7

def initialize(caller, msg)
  super()
  self.update(msg)
  @caller = caller          # bot object
  @bot    = caller          # alias for bot object
end

Instance Method Details

#attach(attachments, options = {}) ⇒ Object



24
25
26
# File 'lib/slackbotsy/message.rb', line 24

def attach(attachments, options = {})
  @caller.attach(attachments, { channel: self['channel_name'] }.merge(options))
end

#methodObject

convenience getter methods for message properties



37
38
39
40
41
# File 'lib/slackbotsy/message.rb', line 37

%w[ token team_id channel_id channel_name timestamp user_id user_name text ].each do |method|
  define_method(method) do
    self.fetch(method, nil)
  end
end

#post(options) ⇒ Object

convenience wrapper in message scope, so we can call it without @caller and set default channel to same as received message



16
17
18
# File 'lib/slackbotsy/message.rb', line 16

def post(options)
  @caller.post({ channel: self['channel_name'] }.merge(options))
end

#post_message(text, options = {}) ⇒ Object



28
29
30
# File 'lib/slackbotsy/message.rb', line 28

def post_message(text, options = {})
  @caller.post_message(text, { channel: self['channel_name'] }.merge(options))
end

#say(text, options = {}) ⇒ Object



20
21
22
# File 'lib/slackbotsy/message.rb', line 20

def say(text, options = {})
  @caller.say(text, { channel: self['channel_name'] }.merge(options))
end

#upload(options = {}) ⇒ Object



32
33
34
# File 'lib/slackbotsy/message.rb', line 32

def upload(options = {})
  @caller.upload({ channel: self['channel_name'] }.merge(options))
end