Module: Slack::Web::Api::Endpoints::Chat

Included in:
Slack::Web::Api::Endpoints
Defined in:
lib/slack/web/api/endpoints/chat.rb

Instance Method Summary collapse

Instance Method Details

#chat_delete(options = {}) ⇒ Object

This method deletes a message from a channel.

Options Hash (options):

  • :ts (timestamp)

    Timestamp of the message to be deleted.

  • :channel (channel)

    Channel containing the message to be deleted.

See Also:


17
18
19
20
21
22
# File 'lib/slack/web/api/endpoints/chat.rb', line 17

def chat_delete(options = {})
  throw ArgumentError.new('Required arguments :ts missing') if options[:ts].nil?
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
  options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
  post('chat.delete', options)
end

#chat_postMessage(options = {}) ⇒ Object

This method posts a message to a public channel, private group, or IM channel.

Options Hash (options):

  • :channel (channel)

    Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name. See below for more details.

  • :text (Object)

    Text of the message to send. See below for an explanation of formatting.

  • :username (Object)

    Name of bot.

  • :as_user (Object)

    Pass true to post the message as the authed user, instead of as a bot.

  • :parse (Object)

    Change how messages are treated. See below.

  • :link_names (Object)

    Find and link channel names and usernames.

  • :attachments (Object)

    Structured message attachments.

  • :unfurl_links (Object)

    Pass true to enable unfurling of primarily text-based content.

  • :unfurl_media (Object)

    Pass false to disable unfurling of media content.

  • :icon_url (Object)

    URL to an image to use as the icon for this message.

  • :icon_emoji (Object)

    emoji to use as the icon for this message. Overrides icon_url.

See Also:


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/slack/web/api/endpoints/chat.rb', line 51

def chat_postMessage(options = {})
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
  throw ArgumentError.new('Required arguments :text or :attachments missing') if options[:text].nil? && options[:attachments].nil?
  # attachments must be passed as an encoded JSON string
  if options.key?(:attachments)
    attachments = options[:attachments]
    attachments = JSON.dump(attachments) unless attachments.is_a?(String)
    options = options.merge(attachments: attachments)
  end
  post('chat.postMessage', options)
end

#chat_update(options = {}) ⇒ Object

This method updates a message in a channel.

Options Hash (options):

  • :ts (timestamp)

    Timestamp of the message to be updated.

  • :channel (channel)

    Channel containing the message to be updated.

  • :text (Object)

    New text for the message, using the default formatting rules.

  • :attachments (Object)

    Structured message attachments.

  • :parse (Object)

    Change how messages are treated. See below.

  • :link_names (Object)

    Find and link channel names and usernames.

See Also:


80
81
82
83
84
85
86
# File 'lib/slack/web/api/endpoints/chat.rb', line 80

def chat_update(options = {})
  throw ArgumentError.new('Required arguments :ts missing') if options[:ts].nil?
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
  throw ArgumentError.new('Required arguments :text missing') if options[:text].nil?
  options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
  post('chat.update', options)
end