Class: Slack::BlockKit::Layout::Actions

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

Overview

A block that is used to hold interactive elements.

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

Constant Summary collapse

TYPE =
'actions'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block_id: nil) {|_self| ... } ⇒ Actions

Returns a new instance of Actions.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
# File 'lib/slack/block_kit/layout/actions.rb', line 14

def initialize(block_id: nil)
  @block_id = block_id
  @elements = []

  yield(self) if block_given?
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



12
13
14
# File 'lib/slack/block_kit/layout/actions.rb', line 12

def elements
  @elements
end

Instance Method Details

#append(element) ⇒ Object



148
149
150
151
152
# File 'lib/slack/block_kit/layout/actions.rb', line 148

def append(element)
  @elements << element

  self
end

#as_jsonObject



154
155
156
157
158
159
160
# File 'lib/slack/block_kit/layout/actions.rb', line 154

def as_json(*)
  {
    type: TYPE,
    elements: @elements.map(&:as_json),
    block_id: @block_id
  }.compact
end

#button(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/slack/block_kit/layout/actions.rb', line 21

def button(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
  element = Element::Button.new(
    text: text,
    action_id: action_id,
    style: style,
    emoji: emoji,
    url: url,
    value: value
  )

  yield(element) if block_given?

  append(element)
end

#channel_select(placeholder:, action_id:, initial: nil, emoji: nil, response_url_enabled: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/slack/block_kit/layout/actions.rb', line 36

def channel_select(placeholder:, action_id:, initial: nil, emoji: nil, response_url_enabled: nil)
  element = Element::ChannelsSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    emoji: emoji,
    response_url_enabled: response_url_enabled
  )

  yield(element) if block_given?

  append(element)
end

#checkboxes(action_id:) {|element| ... } ⇒ Object

Yields:

  • (element)


138
139
140
141
142
143
144
145
146
# File 'lib/slack/block_kit/layout/actions.rb', line 138

def checkboxes(action_id:)
  element = Element::Checkboxes.new(
    action_id: action_id
  )

  yield(element) if block_given?

  append(element)
end

#conversation_select(placeholder:, action_id:, initial: nil, emoji: nil, default_to_current_conversation: nil, response_url_enabled: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/slack/block_kit/layout/actions.rb', line 50

def conversation_select(placeholder:, action_id:, initial: nil, emoji: nil, default_to_current_conversation: nil, response_url_enabled: nil)
  element = Element::ConversationsSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    emoji: emoji,
    default_to_current_conversation: default_to_current_conversation,
    response_url_enabled: response_url_enabled
  )

  yield(element) if block_given?

  append(element)
end

#datepicker(action_id:, placeholder: nil, initial: nil, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/slack/block_kit/layout/actions.rb', line 65

def datepicker(action_id:, placeholder: nil, initial: nil, emoji: nil)
  element = Element::Datepicker.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    emoji: emoji
  )

  yield(element) if block_given?

  append(element)
end

#external_select(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/slack/block_kit/layout/actions.rb', line 91

def external_select(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil)
  element = Element::ExternalSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    min_query_length: min_query_length,
    emoji: emoji
  )

  yield(element) if block_given?

  append(element)
end

#overflow_menu(action_id:) {|element| ... } ⇒ Object

Yields:

  • (element)


105
106
107
108
109
110
111
# File 'lib/slack/block_kit/layout/actions.rb', line 105

def overflow_menu(action_id:)
  element = Element::OverflowMenu.new(action_id: action_id)

  yield(element) if block_given?

  append(element)
end

#static_select(placeholder:, action_id:, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/slack/block_kit/layout/actions.rb', line 113

def static_select(placeholder:, action_id:, emoji: nil)
  element = Element::StaticSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    emoji: emoji
  )

  yield(element) if block_given?

  append(element)
end

#timepicker(action_id:, placeholder: nil, initial: nil, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/slack/block_kit/layout/actions.rb', line 78

def timepicker(action_id:, placeholder: nil, initial: nil, emoji: nil)
  element = Element::Timepicker.new(
    placeholder: placeholder,
    action_id: action_id,
    initial: initial,
    emoji: emoji
  )

  yield(element) if block_given?

  append(element)
end

#users_select(placeholder:, action_id:, initial: nil, emoji: nil) {|element| ... } ⇒ Object

Yields:

  • (element)


125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/slack/block_kit/layout/actions.rb', line 125

def users_select(placeholder:, action_id:, initial: nil, emoji: nil)
  element = Element::UsersSelect.new(
    placeholder: placeholder,
    action_id: action_id,
    emoji: emoji,
    initial: initial
  )

  yield(element) if block_given?

  append(element)
end