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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :ts (timestamp)

    Timestamp of the message to be deleted.

  • :channel (channel)

    Channel containing the message to be deleted.

  • :as_user (Object)

    Pass true to delete the message as the authed user. Bot users in this context are considered authed users.

See Also:



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

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_meMessage(options = {}) ⇒ Object

This method sends a me message to a channel from the calling user.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    Channel to send message to. Can be a public channel, private group or IM channel. Can be an encoded ID, or a name.

  • :text (Object)

    Text of the message to send.

See Also:



35
36
37
38
39
# File 'lib/slack/web/api/endpoints/chat.rb', line 35

def chat_meMessage(options = {})
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
  throw ArgumentError.new('Required arguments :text missing') if options[:text].nil?
  post('chat.meMessage', options)
end

#chat_postMessage(options = {}) ⇒ Object

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

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

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. This field is usually required, unless you’re providing only attachments instead.

  • :parse (Object)

    Change how messages are treated. Defaults to none. 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.

  • :username (Object)

    Set your bot’s user name. Must be used in conjunction with as_user set to false, otherwise ignored. See authorship below.

  • :as_user (Object)

    Pass true to post the message as the authed user, instead of as a bot. Defaults to false. See authorship below.

  • :icon_url (Object)

    URL to an image to use as the icon for this message. Must be used in conjunction with as_user set to false, otherwise ignored. See authorship below.

  • :icon_emoji (Object)

    Emoji to use as the icon for this message. Overrides icon_url. Must be used in conjunction with as_user set to false, otherwise ignored. See authorship below.

  • :thread_ts (Object)

    Provide another message’s ts value to make this message a reply. Avoid using a reply’s ts value; use its parent instead.

  • :reply_broadcast (Object)

    Used in conjunction with thread_ts and indicates whether reply should be made visible to everyone in the channel or conversation. Defaults to false.

See Also:



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/slack/web/api/endpoints/chat.rb', line 72

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_unfurl(options = {}) ⇒ Object

This method attaches Slack app unfurl behavior to a specified and relevant message. A user token is required as this method does not support bot user tokens.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    Channel ID of the message.

  • :ts (timestamp)

    Timestamp of the message to add unfurl behavior to.

  • :unfurls (Object)

    JSON mapping a set of URLs from the message to their unfurl attachments.

  • :user_auth_required (Object)

    Set to true or 1 to indicate the user must install your Slack app to trigger unfurls for this domain.

See Also:



97
98
99
100
101
102
103
# File 'lib/slack/web/api/endpoints/chat.rb', line 97

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

#chat_update(options = {}) ⇒ Object

This method updates a message in a channel. Though related to chat.postMessage, some parameters of chat.update are handled differently.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

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. Defaults to client, unlike chat.postMessage. See below.

  • :link_names (Object)

    Find and link channel names and usernames. Defaults to none. This parameter should be used in conjunction with parse. To set link_names to 1, specify a parse mode of full.

  • :as_user (Object)

    Pass true to update the message as the authed user. Bot users in this context are considered authed users.

See Also:



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/slack/web/api/endpoints/chat.rb', line 124

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 or :attachments missing') if options[:text].nil? && options[:attachments].nil?
  options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
  # 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.update', options)
end