Class: Slack::BlockKit::Element::Button

Inherits:
Object
  • Object
show all
Includes:
Composition::ConfirmationDialog::Confirmable
Defined in:
lib/slack/block_kit/element/button.rb

Overview

An interactive element that inserts a button. The button can be a trigger for anything from opening a simple link to starting a complex workflow.

api.slack.com/reference/messaging/block-elements#button

Constant Summary collapse

TYPE =
'button'

Instance Method Summary collapse

Methods included from Composition::ConfirmationDialog::Confirmable

#confirmation_dialog, included

Constructor Details

#initialize(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil) {|_self| ... } ⇒ Button

Returns a new instance of Button.

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
20
21
22
23
24
# File 'lib/slack/block_kit/element/button.rb', line 16

def initialize(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
  @text = Composition::PlainText.new(text: text, emoji: emoji)
  @action_id = action_id
  @url = url
  @style = style
  @value = value

  yield(self) if block_given?
end

Instance Method Details

#as_jsonObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/slack/block_kit/element/button.rb', line 26

def as_json(*)
  {
    type: TYPE,
    text: @text.as_json,
    action_id: @action_id,
    url: @url,
    value: @value,
    style: @style,
    confirm: confirm&.as_json
  }.compact
end