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

Execute a slash command in a public channel (undocumented)

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    Channel to execute the command in.

  • :command (Object)

    Slash command to be executed. Leading backslash is required.

  • :text (Object)

    Additional parameters provided to the slash command.

See Also:



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

def chat_command(options = {})
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
  throw ArgumentError.new('Required arguments :command missing') if options[:command].nil?
  options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
  logger.warn('The chat.command method is undocumented.')
  post('chat.command', options)
end

#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):

  • :channel (channel)

    Channel containing the message to be deleted.

  • :ts (timestamp)

    Timestamp of the message to be deleted.

  • :as_user (Object)

    Pass true to delete the message as the authed user with chat:write:user scope. Bot users in this context are considered authed users. If unused or false, the message will be deleted with chat:write:bot scope.

See Also:



37
38
39
40
41
42
# File 'lib/slack/web/api/endpoints/chat.rb', line 37

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

#chat_deleteScheduledMessage(options = {}) ⇒ Object

This method deletes a pending scheduled message before it is sent.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    The channel the scheduled_message is posting to.

  • :scheduled_message_id (Object)

    scheduled_message_id returned from call to chat.scheduleMessage.

  • :as_user (Object)

    Pass true to delete the message as the authed user with chat:write:user scope. Bot users in this context are considered authed users. If unused or false, the message will be deleted with chat:write:bot scope.

See Also:



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

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

Easily exchange a message timestamp and a channel ID for a friendly HTTP-based permalink to that message. Handles message threads and all conversation types.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    The ID of the conversation or channel containing the message.

  • :message_ts (Object)

    A message’s ts value, uniquely identifying it within a channel.

See Also:



71
72
73
74
75
76
# File 'lib/slack/web/api/endpoints/chat.rb', line 71

def chat_getPermalink(options = {})
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
  throw ArgumentError.new('Required arguments :message_ts missing') if options[:message_ts].nil?
  options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
  post('chat.getPermalink', 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:



87
88
89
90
91
# File 'lib/slack/web/api/endpoints/chat.rb', line 87

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

This method posts an ephemeral message, which is visible only to the assigned user in a specific public channel, private channel, or private conversation.

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.

  • :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.

  • :user (user)

    id of the user who will receive the ephemeral message. The user should be in the channel specified by the channel argument.

  • :as_user (Object)

    Pass true to post the message as the authed user. Defaults to true if the chat:write:bot scope is not included. Otherwise, defaults to false.

  • :attachments (Object)

    A JSON-based array of structured attachments, presented as a URL-encoded string.

  • :blocks (Object)

    A JSON-based array of structured blocks, presented as a URL-encoded string.

  • :link_names (Object)

    Find and link channel names and usernames.

  • :parse (Object)

    Change how messages are treated. Defaults to none. See below.

  • :thread_ts (Object)

    Provide another message’s ts value to post this message in a thread. Avoid using a reply’s ts value; use its parent’s value instead. Ephemeral messages in threads are only shown if there is already an active thread.

See Also:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/slack/web/api/endpoints/chat.rb', line 116

def chat_postEphemeral(options = {})
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
  throw ArgumentError.new('Required arguments :text, :attachments or :blocks missing') if options[:text].nil? && options[:attachments].nil? && options[:blocks].nil?
  throw ArgumentError.new('Required arguments :user missing') if options[:user].nil?
  options = options.merge(user: users_id(options)['user']['id']) if options[:user]
  # 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
  # blocks must be passed as an encoded JSON string
  if options.key?(:blocks)
    blocks = options[:blocks]
    blocks = JSON.dump(blocks) unless blocks.is_a?(String)
    options = options.merge(blocks: blocks)
  end
  post('chat.postEphemeral', 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. Provide no more than 40,000 characters or risk truncation.

  • :as_user (Object)

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

  • :attachments (Object)

    A JSON-based array of structured attachments, presented as a URL-encoded string.

  • :blocks (Object)

    A JSON-based array of structured blocks, presented as a URL-encoded string.

  • :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.

  • :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.

  • :link_names (Object)

    Find and link channel names and usernames.

  • :mrkdwn (Object)

    Disable Slack markup parsing by setting to false. Enabled by default.

  • :parse (Object)

    Change how messages are treated. Defaults to none. See below.

  • :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.

  • :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.

  • :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.

See Also:



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/slack/web/api/endpoints/chat.rb', line 171

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

#chat_scheduleMessage(options = {}) ⇒ Object

This method schedules a message for delivery to a public channel, private channel, or direct message/IM channel at a specified time in the future.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :channel (channel)

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

  • :post_at (Object)

    Unix EPOCH timestamp of time in future to send the message.

  • :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. Provide no more than 40,000 characters or risk truncation.

  • :as_user (Object)

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

  • :attachments (Object)

    A JSON-based array of structured attachments, presented as a URL-encoded string.

  • :blocks (Object)

    A JSON-based array of structured blocks, presented as a URL-encoded string.

  • :link_names (Object)

    Find and link channel names and usernames.

  • :parse (Object)

    Change how messages are treated. Defaults to none. See below.

  • :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.

  • :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.

  • :unfurl_links (Object)

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

  • :unfurl_media (Object)

    Pass false to disable unfurling of media content.

See Also:



218
219
220
221
222
223
# File 'lib/slack/web/api/endpoints/chat.rb', line 218

def chat_scheduleMessage(options = {})
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
  throw ArgumentError.new('Required arguments :post_at missing') if options[:post_at].nil?
  throw ArgumentError.new('Required arguments :text missing') if options[:text].nil?
  post('chat.scheduleMessage', 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)

    URL-encoded JSON map with keys set to URLs featured in the the message, pointing to their unfurl blocks or message attachments.

  • :user_auth_message (Object)

    Provide a simply-formatted string to send as an ephemeral message to the user as invitation to authenticate further and enable full unfurling behavior.

  • :user_auth_required (Object)

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

  • :user_auth_url (Object)

    Send users to this custom URL where they will complete authentication in your app to fully trigger unfurling. Value should be properly URL-encoded.

See Also:



242
243
244
245
246
247
248
# File 'lib/slack/web/api/endpoints/chat.rb', line 242

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):

  • :channel (channel)

    Channel containing the message to be updated.

  • :text (Object)

    New text for the message, using the default formatting rules. It’s not required when presenting attachments.

  • :ts (timestamp)

    Timestamp of the message to be updated.

  • :as_user (Object)

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

  • :attachments (Object)

    A JSON-based array of structured attachments, presented as a URL-encoded string. This field is required when not presenting text.

  • :blocks (Object)

    A JSON-based array of structured blocks, presented as a URL-encoded string.

  • :link_names (Object)

    Find and link channel names and usernames. Defaults to none. See below.

  • :parse (Object)

    Change how messages are treated. Defaults to client, unlike chat.postMessage. See below.

See Also:



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/slack/web/api/endpoints/chat.rb', line 271

def chat_update(options = {})
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
  throw ArgumentError.new('Required arguments :text, :attachments or :blocks missing') if options[:text].nil? && options[:attachments].nil? && options[:blocks].nil?
  throw ArgumentError.new('Required arguments :ts missing') if options[:ts].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
  # blocks must be passed as an encoded JSON string
  if options.key?(:blocks)
    blocks = options[:blocks]
    blocks = JSON.dump(blocks) unless blocks.is_a?(String)
    options = options.merge(blocks: blocks)
  end
  post('chat.update', options)
end