Class: Slack::API::Chat

Inherits:
Base
  • Object
show all
Defined in:
lib/laziness/api/chat.rb

Instance Attribute Summary

Attributes inherited from Base

#access_token

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Slack::API::Base

Instance Method Details

#create(text, channel, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/laziness/api/chat.rb', line 4

def create(text, channel, options={})
  if (options.has_key?(:attachments))
    attachments = options[:attachments]
    attachments = JSON.dump(attachments) unless attachments.is_a?(String)
    options = options.merge(attachments: attachments)
  end
  response = request :post, 'chat.postMessage', { text: text, channel: channel }.merge(options)
  Slack::Chat.parse response, 'message'
end

#delete(channel, timestamp) ⇒ Object



14
15
16
# File 'lib/laziness/api/chat.rb', line 14

def delete(channel, timestamp)
  with_nil_response { request :post, 'chat.delete', ts: timestamp, channel: channel }
end

#update(text, channel, timestamp, options = {}) ⇒ Object



18
19
20
21
22
# File 'lib/laziness/api/chat.rb', line 18

def update(text, channel, timestamp, options={})
  response = request :post, 'chat.update',
    { text: text, channel: channel, ts: timestamp }.merge(options)
  Slack::Chat.parse response, 'message'
end