Class: Lita::Adapters::Slack::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/adapters/slack/attachment.rb

Overview

A Slack attachment object.

Instance Method Summary collapse

Constructor Details

#initialize(text, **options) ⇒ Attachment

Returns a new instance of Attachment.

Parameters:

  • text (String)

    The main text of the message.

  • options (Hash)

    Keyword arguments supporting all the option supported by Slack's attachment API. These options will be passed to Slack as provided, with the exception that the :fallback option defaults to the value of text (the first argument to this method) and any value specified for the :text option will be overwritten by the explicit text argument.

Since:

  • 1.6.0


15
16
17
18
# File 'lib/lita/adapters/slack/attachment.rb', line 15

def initialize(text, **options)
  self.text = text
  self.options = options
end

Instance Method Details

#to_hashHash

Converts the attachment into a hash, suitable for being sent to the Slack API.

Returns:

  • (Hash)

    The converted hash.

Since:

  • 1.6.0


22
23
24
25
26
27
# File 'lib/lita/adapters/slack/attachment.rb', line 22

def to_hash
  options.merge({
    fallback: options[:fallback] || text,
    text: text,
  })
end