Class: Slack::BlockKit::Layout::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/block_kit/layout/image.rb

Overview

A simple image block, designed to make those cat photos really pop.

api.slack.com/reference/messaging/blocks#context

Constant Summary collapse

TYPE =
'image'

Instance Method Summary collapse

Constructor Details

#initialize(url:, alt_text:, title: nil, block_id: nil, emoji: nil) ⇒ Image

Returns a new instance of Image.



12
13
14
15
16
17
18
19
20
# File 'lib/slack/block_kit/layout/image.rb', line 12

def initialize(url:, alt_text:, title: nil, block_id: nil, emoji: nil)
  @image_url = url
  @alt_text = alt_text
  @block_id = block_id
  @title = title && Composition::PlainText.new(
    text: title,
    emoji: emoji
  )
end

Instance Method Details

#as_jsonObject



22
23
24
25
26
27
28
29
30
# File 'lib/slack/block_kit/layout/image.rb', line 22

def as_json(*)
  {
    type: TYPE,
    image_url: @image_url,
    alt_text: @alt_text,
    title: @title&.as_json,
    block_id: @block_id
  }.compact
end