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

Appends text to an existing streaming conversation.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    An encoded ID that represents a channel, private group, or DM.

  • :ts (timestamp)

    The timestamp of the streaming message.

  • :markdown_text (string)

    Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is what will be appended to the message received so far.

Raises:

  • (ArgumentError)

See Also:



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

def chat_appendStream(options = {})
  raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
  raise ArgumentError, 'Required arguments :ts missing' if options[:ts].nil?
  raise ArgumentError, 'Required arguments :markdown_text missing' if options[:markdown_text].nil?
  options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
  post('chat.appendStream', options)
end

#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.

Raises:

  • (ArgumentError)

See Also:



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

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

#chat_delete(options = {}) ⇒ Object

Deletes a message.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :as_user (boolean) — default: Legacy

    Pass true to delete the message as the authed user with chat:write:user scope. Bot users in this context are considered authed users. See legacy as_user parameter below.

  • :channel (channel)

    Channel containing the message to be deleted.

  • :ts (timestamp)

    Timestamp of the message to be deleted.

Raises:

  • (ArgumentError)

See Also:



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

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

#chat_deleteScheduledMessage(options = {}) ⇒ Object

Deletes a pending scheduled message from the queue.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :as_user (boolean)

    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.

  • :channel (channel)

    The channel the scheduled_message is posting to.

  • :scheduled_message_id (string)

    scheduled_message_id returned from call to chat.scheduleMessage.

Raises:

  • (ArgumentError)

See Also:



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

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

Retrieve a permalink URL for a specific extant message

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 (string)

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

Raises:

  • (ArgumentError)

See Also:



91
92
93
94
95
96
# File 'lib/slack/web/api/endpoints/chat.rb', line 91

def chat_getPermalink(options = {})
  raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
  raise ArgumentError, 'Required arguments :message_ts missing' if options[:message_ts].nil?
  options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
  post('chat.getPermalink', options)
end

#chat_meMessage(options = {}) ⇒ Object

Share a me message into a channel.

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 (string)

    Text of the message to send.

Raises:

  • (ArgumentError)

See Also:



107
108
109
110
111
# File 'lib/slack/web/api/endpoints/chat.rb', line 107

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

#chat_postEphemeral(options = {}) ⇒ Object

Sends an ephemeral message to a user in a channel.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :as_user (boolean) — default: Legacy

    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 (string)

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

  • :blocks (string)

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

  • :channel (channel)

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

  • :icon_emoji (string)

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

  • :icon_url (string)

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

  • :link_names (boolean)

    Find and link channel names and usernames.

  • :markdown_text (string)

    Accepts message text formatted in markdown. This argument should not be used in conjunction with blocks or text. Limit this field to 12,000 characters.

  • :parse (string)

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

  • :text (string)

    How this field works and whether it is required depends on other fields you use in your API call. See below for more detail.

  • :thread_ts (string)

    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.

  • :user (user)

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

  • :username (string)

    Set your bot’s user name.

Raises:

  • (ArgumentError)

See Also:



144
145
146
147
148
149
150
151
# File 'lib/slack/web/api/endpoints/chat.rb', line 144

def chat_postEphemeral(options = {})
  raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
  raise ArgumentError, 'Required arguments :user missing' if options[:user].nil?
  raise ArgumentError, 'At least one of :attachments, :blocks, :text is required' if options[:attachments].nil? && options[:blocks].nil? && options[:text].nil?
  options = options.merge(user: users_id(options)['user']['id']) if options[:user]
  options = encode_options_as_json(options, %i[attachments blocks])
  post('chat.postEphemeral', options)
end

#chat_postMessage(options = {}) ⇒ Object

Sends a message to a channel.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :as_user (boolean) — default: Legacy

    Pass true to post the message as the authed user instead of as a bot. Defaults to false. Can only be used by classic apps. See legacy as_user parameter below.

  • :attachments (["string", "boolean"])

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

  • :blocks (string)

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

  • :channel (channel)

    An encoded ID or channel name that represents a channel, private group, or IM channel to send the message to. See below for more details.

  • :current_draft_last_updated_ts (string)

    This field represents the timestamp of the draft’s last update at the time this API is called. If the current message is a draft, this field can be provided to ensure synchronization with the server.

  • :icon_emoji (string)

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

  • :icon_url (string)

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

  • :link_names (boolean)

    Find and link user groups. No longer supports linking individual users; use syntax shown in Mentioning Users instead.

  • :markdown_text (string)

    Accepts message text formatted in markdown. This argument should not be used in conjunction with blocks or text. Limit this field to 12,000 characters.

  • :metadata (string)

    JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.

  • :mrkdwn (boolean)

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

  • :parse (string)

    Change how messages are treated. See below.

  • :reply_broadcast (boolean)

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

  • :text (string)

    How this field works and whether it is required depends on other fields you use in your API call. See below for more detail.

  • :thread_ts (string)

    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 (boolean)

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

  • :unfurl_media (boolean)

    Pass false to disable unfurling of media content.

  • :username (string)

    Set your bot’s user name.

Raises:

  • (ArgumentError)

See Also:



194
195
196
197
198
199
# File 'lib/slack/web/api/endpoints/chat.rb', line 194

def chat_postMessage(options = {})
  raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
  raise ArgumentError, 'At least one of :attachments, :blocks, :text is required' if options[:attachments].nil? && options[:blocks].nil? && options[:text].nil?
  options = encode_options_as_json(options, %i[attachments blocks metadata])
  post('chat.postMessage', options)
end

#chat_scheduleMessage(options = {}) ⇒ Object

Schedules a message to be sent to a channel.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :as_user (boolean)

    Set to true to post the message as the authed user, instead of as a bot. Defaults to false. Cannot be used by new Slack apps. See chat.postMessage.

  • :attachments (string)

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

  • :blocks (string)

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

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

  • :link_names (boolean)

    Find and link user groups. No longer supports linking individual users; use syntax shown in Mentioning Users instead.

  • :markdown_text (string)

    Accepts message text formatted in markdown. This argument should not be used in conjunction with blocks or text. Limit this field to 12,000 characters.

  • :parse (enum)

    Change how messages are treated. See chat.postMessage.

  • :post_at (integer)

    Unix timestamp representing the future time the message should post to Slack.

  • :reply_broadcast (boolean)

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

  • :text (string)

    How this field works and whether it is required depends on other fields you use in your API call. See below for more detail.

  • :thread_ts (string)

    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 (boolean)

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

  • :unfurl_media (boolean)

    Pass false to disable unfurling of media content.

  • :metadata (string)

    JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.

Raises:

  • (ArgumentError)

See Also:



234
235
236
237
238
239
240
# File 'lib/slack/web/api/endpoints/chat.rb', line 234

def chat_scheduleMessage(options = {})
  raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
  raise ArgumentError, 'Required arguments :post_at missing' if options[:post_at].nil?
  raise ArgumentError, 'At least one of :attachments, :blocks, :text is required' if options[:attachments].nil? && options[:blocks].nil? && options[:text].nil?
  options = encode_options_as_json(options, %i[attachments blocks metadata])
  post('chat.scheduleMessage', options)
end

#chat_startStream(options = {}) ⇒ Object

Starts a new streaming conversation.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    An encoded ID that represents a channel, private group, or DM.

  • :markdown_text (string)

    Accepts message text formatted in markdown. Limit this field to 12,000 characters.

  • :thread_ts (string)

    Provide another message’s ts value to reply to. Streamed messages should always be replies to a user request.

  • :recipient_user_id (Object)

    The encoded ID of the user to receive the streaming text. Required when streaming to channels.

  • :recipient_team_id (string)

    The encoded ID of the team the user receiving the streaming text belongs to. Required when streaming to channels.

Raises:

  • (ArgumentError)

See Also:



257
258
259
260
261
262
# File 'lib/slack/web/api/endpoints/chat.rb', line 257

def chat_startStream(options = {})
  raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
  raise ArgumentError, 'Required arguments :thread_ts missing' if options[:thread_ts].nil?
  options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
  post('chat.startStream', options)
end

#chat_stopStream(options = {}) ⇒ Object

Stops a streaming conversation.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    An encoded ID that represents a channel, private group, or DM.

  • :ts (timestamp)

    The timestamp of the streaming message.

  • :markdown_text (string)

    Accepts message text formatted in markdown. Limit this field to 12,000 characters.

  • :blocks (Object)

    A list of blocks that will be rendered at the bottom of the finalized message.

  • :metadata (string)

    JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.

Raises:

  • (ArgumentError)

See Also:



279
280
281
282
283
284
285
# File 'lib/slack/web/api/endpoints/chat.rb', line 279

def chat_stopStream(options = {})
  raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
  raise ArgumentError, 'Required arguments :ts missing' if options[:ts].nil?
  options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
  options = encode_options_as_json(options, %i[metadata])
  post('chat.stopStream', options)
end

#chat_unfurl(options = {}) ⇒ Object

Provide custom unfurl behavior for user-posted URLs

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    Channel ID of the message. Both channel and ts must be provided together, or unfurl_id and source must be provided together.

  • :ts (timestamp)

    Timestamp of the message to add unfurl behavior to.

  • :unfurls (string)

    URL-encoded JSON map with keys set to URLs featured in the the message, pointing to their unfurl blocks or message attachments. Either unfurls or metadata must be provided.

  • :user_auth_message (string)

    Provide a simply-formatted string to send as an ephemeral message to the user as invitation to authenticate further and enable full unfurling behavior. Provides two buttons, Not now or Never ask me again.

  • :user_auth_required (boolean)

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

  • :user_auth_url (string)

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

  • :user_auth_blocks (Object)

    Provide a JSON based array of structured blocks presented as URL-encoded string to send as an ephemeral message to the user as invitation to authenticate further and enable full unfurling behavior.

  • :unfurl_id (string)

    The ID of the link to unfurl. Both unfurl_id and source must be provided together, or channel and ts must be provided together.

  • :source (enum)

    The source of the link to unfurl. The source may either be composer, when the link is inside the message composer, or conversations_history, when the link has been posted to a conversation.

  • :metadata (string)

    JSON object with entity_type and entity_payload fields, presented as a URL-encoded string. Either unfurls or metadata must be provided.

See Also:



312
313
314
315
316
# File 'lib/slack/web/api/endpoints/chat.rb', line 312

def chat_unfurl(options = {})
  options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
  options = encode_options_as_json(options, %i[unfurls user_auth_blocks metadata])
  post('chat.unfurl', options)
end

#chat_update(options = {}) ⇒ Object

Updates a message.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :as_user (["boolean", "string"])

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

  • :attachments (string)

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

  • :blocks (string)

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

  • :markdown_text (string)

    Accepts message text formatted in markdown. This argument should not be used in conjunction with blocks or text. Limit this field to 12,000 characters.

  • :metadata (string)

    JSON object with event_type and event_payload fields, presented as a URL-encoded string. If you don’t include this field, the message’s previous metadata will be retained. To remove previous metadata, include an empty object for this field. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.

  • :channel (channel)

    Channel containing the message to be updated. For direct messages, ensure that this value is a DM ID (starts with D) instead of a User ID (starts with either U or W).

  • :link_names (["boolean", "string"])

    Find and link channel names and usernames. Defaults to none. If you do not specify a value for this field, the original value set for the message will be overwritten with the default, none.

  • :parse (string)

    Change how messages are treated. Defaults to client, unlike chat.postMessage. Accepts either none or full. If you do not specify a value for this field, the original value set for the message will be overwritten with the default, client.

  • :text (string)

    How this field works and whether it is required depends on other fields you use in your API call. See below for more detail.

  • :ts (timestamp)

    Timestamp of the message to be updated.

  • :reply_broadcast (boolean)

    Broadcast an existing thread reply to make it visible to everyone in the channel or conversation.

  • :file_ids (array)

    Array of new file ids that will be sent with this message.

Raises:

  • (ArgumentError)

See Also:



347
348
349
350
351
352
353
354
# File 'lib/slack/web/api/endpoints/chat.rb', line 347

def chat_update(options = {})
  raise ArgumentError, 'Required arguments :channel missing' if options[:channel].nil?
  raise ArgumentError, 'Required arguments :ts missing' if options[:ts].nil?
  raise ArgumentError, 'At least one of :attachments, :blocks, :text is required' if options[:attachments].nil? && options[:blocks].nil? && options[:text].nil?
  options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
  options = encode_options_as_json(options, %i[attachments blocks metadata])
  post('chat.update', options)
end