Method: Slack::Web::Api::Endpoints::Chat#chat_update

Defined in:
lib/slack/web/api/endpoints/chat.rb

#chat_update(options = {}) ⇒ Object

Updates a message.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :channel (channel)

    Channel containing the message to be updated.

  • :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. If you don’t include this field, the message’s previous attachments will be retained. To remove previous attachments, include an empty array for this field.

  • :blocks (Object)

    A JSON-based array of structured blocks, presented as a URL-encoded string. If you don’t include this field, the message’s previous blocks will be retained. To remove previous blocks, include an empty array for this field.

  • :link_names (Object)

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

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

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

See Also:



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/slack/web/api/endpoints/chat.rb', line 282

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