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
# File 'lib/slackbotsy/message.rb', line 7

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

Instance Method Details

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

ditto



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

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

#methodObject

convenience getter methods for message properties



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

%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



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

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

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

ditto



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

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