Method: Slack::Endpoint::Chat#chat_postMessage

Defined in:
lib/slack/endpoint/chat.rb

#chat_postMessage(options = {}) ⇒ Object

Sends a message to a channel.

Parameters:

  • (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :channel (Object)

    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.

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

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

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



116
117
118
119
120
121
# File 'lib/slack/endpoint/chat.rb', line 116

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?
  options[:attachments] = options[:attachments].to_json if options[:attachments].is_a?(Array) || options[:attachments].is_a?(Hash)
  post("chat.postMessage", options)
end