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

Inherits:
Object
  • Object
show all
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 Attribute Summary collapse

Instance Method Summary collapse

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 Attribute Details

#confirmObject

Returns the value of attribute confirm.



14
15
16
# File 'lib/slack/block_kit/element/button.rb', line 14

def confirm
  @confirm
end

Instance Method Details

#as_jsonObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/slack/block_kit/element/button.rb', line 34

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

#confirmation_dialog {|@confirm| ... } ⇒ Object

Yields:



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

def confirmation_dialog
  @confirm = Composition::ConfirmationDialog.new

  yield(@confirm) if block_given?

  @confirm
end