class Slack::BlockKit::Layout::Context

Displays message context, which can include both images and text.

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

Constants

TYPE

Attributes

elements[RW]

Public Class Methods

new(block_id: nil) { |self| ... } click to toggle source
# File lib/slack/block_kit/layout/context.rb, line 14
def initialize(block_id: nil)
  @block_id = block_id
  @elements = []

  yield(self) if block_given?
end

Public Instance Methods

append(element) click to toggle source
# File lib/slack/block_kit/layout/context.rb, line 33
def append(element)
  @elements << element

  self
end
as_json(*) click to toggle source
# File lib/slack/block_kit/layout/context.rb, line 39
def as_json(*)
  {
    type: TYPE,
    elements: @elements.map(&:as_json),
    block_id: @block_id
  }.compact
end
image(url:, alt_text:) click to toggle source
# File lib/slack/block_kit/layout/context.rb, line 21
def image(url:, alt_text:)
  append(Element::Image.new(image_url: url, alt_text: alt_text))
end
mrkdwn(text:, verbatim: nil) click to toggle source
# File lib/slack/block_kit/layout/context.rb, line 29
def mrkdwn(text:, verbatim: nil)
  append(Composition::Mrkdwn.new(text: text, verbatim: verbatim))
end
plain_text(text:, emoji: nil) click to toggle source
# File lib/slack/block_kit/layout/context.rb, line 25
def plain_text(text:, emoji: nil)
  append(Composition::PlainText.new(text: text, emoji: emoji))
end