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

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

#chat_postMessage(options = {}) ⇒ Object

Sends a message to a 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.

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

  • :draft_id (Object)

    The id of the draft associated with the message.

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

  • :text (Object)

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



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/slack/web/api/endpoints/chat.rb', line 180

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