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

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

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

See Also:



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

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