slack-ruby-block-kit 0.10.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.deepsource.toml +15 -0
- data/.github/workflows/ci.yml +33 -0
- data/.rubocop.yml +19 -2
- data/CHANGELOG.md +65 -3
- data/Gemfile +13 -1
- data/Gemfile.lock +66 -43
- data/README.md +3 -1
- data/lib/slack/block_kit.rb +2 -2
- data/lib/slack/block_kit/blocks.rb +18 -0
- data/lib/slack/block_kit/composition/confirmation_dialog.rb +16 -0
- data/lib/slack/block_kit/composition/option.rb +6 -1
- data/lib/slack/block_kit/composition/option_group.rb +2 -2
- data/lib/slack/block_kit/element/button.rb +3 -11
- data/lib/slack/block_kit/element/channels_select.rb +3 -11
- data/lib/slack/block_kit/element/checkboxes.rb +15 -26
- data/lib/slack/block_kit/element/conversations_select.rb +3 -11
- data/lib/slack/block_kit/element/date_picker.rb +3 -9
- data/lib/slack/block_kit/element/external_select.rb +3 -12
- data/lib/slack/block_kit/element/multi_channels_select.rb +3 -12
- data/lib/slack/block_kit/element/multi_conversations_select.rb +3 -12
- data/lib/slack/block_kit/element/multi_external_select.rb +3 -12
- data/lib/slack/block_kit/element/multi_static_select.rb +18 -26
- data/lib/slack/block_kit/element/multi_users_select.rb +3 -12
- data/lib/slack/block_kit/element/overflow_menu.rb +4 -11
- data/lib/slack/block_kit/element/radio_buttons.rb +53 -0
- data/lib/slack/block_kit/element/static_select.rb +20 -25
- data/lib/slack/block_kit/element/timepicker.rb +49 -0
- data/lib/slack/block_kit/element/users_select.rb +3 -11
- data/lib/slack/block_kit/layout/header.rb +29 -0
- data/lib/slack/block_kit/layout/input.rb +196 -3
- data/lib/slack/block_kit/layout/section.rb +11 -4
- data/lib/slack/block_kit/version.rb +7 -0
- data/slack-ruby-block-kit.gemspec +1 -18
- metadata +11 -134
- data/.circleci/config.yml +0 -49
- data/.rubocop_todo.yml +0 -40
@@ -17,8 +17,8 @@ module Slack
|
|
17
17
|
yield(self) if block_given?
|
18
18
|
end
|
19
19
|
|
20
|
-
def option(text:, value:, emoji: nil)
|
21
|
-
@options << Option.new(text: text, value: value, emoji: emoji)
|
20
|
+
def option(text:, value:, emoji: nil, initial: false)
|
21
|
+
@options << Option.new(text: text, value: value, emoji: emoji, initial: initial)
|
22
22
|
|
23
23
|
self
|
24
24
|
end
|
@@ -9,9 +9,9 @@ module Slack
|
|
9
9
|
#
|
10
10
|
# https://api.slack.com/reference/messaging/block-elements#button
|
11
11
|
class Button
|
12
|
-
|
12
|
+
include Composition::ConfirmationDialog::Confirmable
|
13
13
|
|
14
|
-
|
14
|
+
TYPE = 'button'
|
15
15
|
|
16
16
|
def initialize(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
|
17
17
|
@text = Composition::PlainText.new(text: text, emoji: emoji)
|
@@ -23,14 +23,6 @@ module Slack
|
|
23
23
|
yield(self) if block_given?
|
24
24
|
end
|
25
25
|
|
26
|
-
def confirmation_dialog
|
27
|
-
@confirm = Composition::ConfirmationDialog.new
|
28
|
-
|
29
|
-
yield(@confirm) if block_given?
|
30
|
-
|
31
|
-
@confirm
|
32
|
-
end
|
33
|
-
|
34
26
|
def as_json(*)
|
35
27
|
{
|
36
28
|
type: TYPE,
|
@@ -39,7 +31,7 @@ module Slack
|
|
39
31
|
url: @url,
|
40
32
|
value: @value,
|
41
33
|
style: @style,
|
42
|
-
confirm:
|
34
|
+
confirm: confirm&.as_json
|
43
35
|
}.compact
|
44
36
|
end
|
45
37
|
end
|
@@ -13,9 +13,9 @@ module Slack
|
|
13
13
|
#
|
14
14
|
# https://api.slack.com/reference/messaging/block-elements#channel-select
|
15
15
|
class ChannelsSelect
|
16
|
-
|
16
|
+
include Composition::ConfirmationDialog::Confirmable
|
17
17
|
|
18
|
-
|
18
|
+
TYPE = 'channels_select'
|
19
19
|
|
20
20
|
def initialize(placeholder:, action_id:, initial: nil, emoji: nil)
|
21
21
|
@placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
|
@@ -25,21 +25,13 @@ module Slack
|
|
25
25
|
yield(self) if block_given?
|
26
26
|
end
|
27
27
|
|
28
|
-
def confirmation_dialog
|
29
|
-
@confirm = Composition::ConfirmationDialog.new
|
30
|
-
|
31
|
-
yield(@confirm) if block_given?
|
32
|
-
|
33
|
-
self
|
34
|
-
end
|
35
|
-
|
36
28
|
def as_json(*)
|
37
29
|
{
|
38
30
|
type: TYPE,
|
39
31
|
placeholder: @placeholder.as_json,
|
40
32
|
action_id: @action_id,
|
41
33
|
initial_channel: @initial_channel,
|
42
|
-
confirm:
|
34
|
+
confirm: confirm&.as_json
|
43
35
|
}.compact
|
44
36
|
end
|
45
37
|
end
|
@@ -8,56 +8,45 @@ module Slack
|
|
8
8
|
#
|
9
9
|
# https://api.slack.com/reference/messaging/block-elements#checkboxes
|
10
10
|
class Checkboxes
|
11
|
-
|
11
|
+
include Composition::ConfirmationDialog::Confirmable
|
12
12
|
|
13
|
-
|
13
|
+
TYPE = 'checkboxes'
|
14
14
|
|
15
15
|
def initialize(action_id:)
|
16
16
|
@action_id = action_id
|
17
17
|
@options = []
|
18
|
-
@initial_options = []
|
19
|
-
@confirm = nil
|
20
18
|
|
21
19
|
yield(self) if block_given?
|
22
20
|
end
|
23
21
|
|
24
|
-
def option(value:, text:, description: nil)
|
22
|
+
def option(value:, text:, initial: false, description: nil)
|
25
23
|
@options << Composition::Option.new(
|
26
24
|
value: value,
|
27
25
|
text: text,
|
28
|
-
description: description
|
29
|
-
|
30
|
-
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
34
|
-
def initial(value:, text:, description: nil)
|
35
|
-
@initial_options << Composition::Option.new(
|
36
|
-
value: value,
|
37
|
-
text: text,
|
38
|
-
description: description
|
26
|
+
description: description,
|
27
|
+
initial: initial
|
39
28
|
)
|
40
29
|
|
41
30
|
self
|
42
31
|
end
|
43
32
|
|
44
|
-
def confirmation_dialog
|
45
|
-
@confirm = Composition::ConfirmationDialog.new
|
46
|
-
|
47
|
-
yield(@confirm) if block_given?
|
48
|
-
|
49
|
-
@confirm
|
50
|
-
end
|
51
|
-
|
52
33
|
def as_json(*)
|
53
34
|
{
|
54
35
|
type: TYPE,
|
55
36
|
action_id: @action_id,
|
56
37
|
options: @options.map(&:as_json),
|
57
|
-
initial_options:
|
58
|
-
confirm:
|
38
|
+
initial_options: initial_options&.map(&:as_json),
|
39
|
+
confirm: confirm&.as_json
|
59
40
|
}.compact
|
60
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def initial_options
|
46
|
+
initial = @options.select(&:initial?)
|
47
|
+
|
48
|
+
initial.empty? ? nil : initial
|
49
|
+
end
|
61
50
|
end
|
62
51
|
end
|
63
52
|
end
|
@@ -14,9 +14,9 @@ module Slack
|
|
14
14
|
#
|
15
15
|
# https://api.slack.com/reference/messaging/block-elements#conversation-select
|
16
16
|
class ConversationsSelect
|
17
|
-
|
17
|
+
include Composition::ConfirmationDialog::Confirmable
|
18
18
|
|
19
|
-
|
19
|
+
TYPE = 'conversations_select'
|
20
20
|
|
21
21
|
def initialize(placeholder:, action_id:, initial: nil, emoji: nil)
|
22
22
|
@placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
|
@@ -27,14 +27,6 @@ module Slack
|
|
27
27
|
yield(self) if block_given?
|
28
28
|
end
|
29
29
|
|
30
|
-
def confirmation_dialog
|
31
|
-
@confirm = Composition::ConfirmationDialog.new
|
32
|
-
|
33
|
-
yield(@confirm) if block_given?
|
34
|
-
|
35
|
-
self
|
36
|
-
end
|
37
|
-
|
38
30
|
def filter(only: nil,
|
39
31
|
exclude_external_shared_channels: nil,
|
40
32
|
exclude_bot_users: nil)
|
@@ -53,7 +45,7 @@ module Slack
|
|
53
45
|
placeholder: @placeholder.as_json,
|
54
46
|
action_id: @action_id,
|
55
47
|
initial_conversation: @initial_conversation,
|
56
|
-
confirm:
|
48
|
+
confirm: confirm&.as_json,
|
57
49
|
filter: @filter&.as_json
|
58
50
|
}.compact
|
59
51
|
end
|
@@ -10,6 +10,8 @@ module Slack
|
|
10
10
|
#
|
11
11
|
# https://api.slack.com/reference/messaging/block-elements#datepicker
|
12
12
|
class DatePicker
|
13
|
+
include Composition::ConfirmationDialog::Confirmable
|
14
|
+
|
13
15
|
TYPE = 'datepicker'
|
14
16
|
|
15
17
|
def initialize(action_id:, placeholder: nil, initial: nil, emoji: nil)
|
@@ -25,21 +27,13 @@ module Slack
|
|
25
27
|
yield(self) if block_given?
|
26
28
|
end
|
27
29
|
|
28
|
-
def confirmation_dialog
|
29
|
-
@confirm = Composition::ConfirmationDialog.new
|
30
|
-
|
31
|
-
yield(@confirm) if block_given?
|
32
|
-
|
33
|
-
self
|
34
|
-
end
|
35
|
-
|
36
30
|
def as_json(*)
|
37
31
|
{
|
38
32
|
type: TYPE,
|
39
33
|
action_id: @action_id,
|
40
34
|
placeholder: @placeholder&.as_json,
|
41
35
|
initial_date: @initial_date,
|
42
|
-
confirm:
|
36
|
+
confirm: confirm&.as_json
|
43
37
|
}.compact
|
44
38
|
end
|
45
39
|
end
|
@@ -19,28 +19,19 @@ module Slack
|
|
19
19
|
#
|
20
20
|
# https://api.slack.com/reference/messaging/block-elements#external-select
|
21
21
|
class ExternalSelect
|
22
|
-
|
22
|
+
include Composition::ConfirmationDialog::Confirmable
|
23
23
|
|
24
|
-
|
24
|
+
TYPE = 'external_select'
|
25
25
|
|
26
26
|
def initialize(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil)
|
27
27
|
@placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
|
28
28
|
@action_id = action_id
|
29
29
|
@initial_option = initial
|
30
30
|
@min_query_length = min_query_length
|
31
|
-
@confirm = nil
|
32
31
|
|
33
32
|
yield(self) if block_given?
|
34
33
|
end
|
35
34
|
|
36
|
-
def confirmation_dialog
|
37
|
-
@confirm = Composition::ConfirmationDialog.new
|
38
|
-
|
39
|
-
yield(@confirm) if block_given?
|
40
|
-
|
41
|
-
self
|
42
|
-
end
|
43
|
-
|
44
35
|
def as_json(*)
|
45
36
|
{
|
46
37
|
type: TYPE,
|
@@ -48,7 +39,7 @@ module Slack
|
|
48
39
|
action_id: @action_id,
|
49
40
|
initial_option: @initial_option&.as_json,
|
50
41
|
min_query_length: @min_query_length,
|
51
|
-
confirm:
|
42
|
+
confirm: confirm&.as_json
|
52
43
|
}.compact
|
53
44
|
end
|
54
45
|
end
|
@@ -13,35 +13,26 @@ module Slack
|
|
13
13
|
#
|
14
14
|
# https://api.slack.com/reference/block-kit/block-elements#channel_multi_select
|
15
15
|
class MultiChannelsSelect
|
16
|
-
|
16
|
+
include Composition::ConfirmationDialog::Confirmable
|
17
17
|
|
18
|
-
|
18
|
+
TYPE = 'multi_channels_select'
|
19
19
|
|
20
20
|
def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
|
21
21
|
@placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
|
22
22
|
@action_id = action_id
|
23
23
|
@initial_channels = initial
|
24
|
-
@confirm = nil
|
25
24
|
@max_selected_items = max_selected_items
|
26
25
|
|
27
26
|
yield(self) if block_given?
|
28
27
|
end
|
29
28
|
|
30
|
-
def confirmation_dialog
|
31
|
-
@confirm = Composition::ConfirmationDialog.new
|
32
|
-
|
33
|
-
yield(@confirm) if block_given?
|
34
|
-
|
35
|
-
self
|
36
|
-
end
|
37
|
-
|
38
29
|
def as_json(*)
|
39
30
|
{
|
40
31
|
type: TYPE,
|
41
32
|
placeholder: @placeholder.as_json,
|
42
33
|
action_id: @action_id,
|
43
34
|
initial_channels: @initial_channels,
|
44
|
-
confirm:
|
35
|
+
confirm: confirm&.as_json,
|
45
36
|
max_selected_items: @max_selected_items
|
46
37
|
}.compact
|
47
38
|
end
|
@@ -14,29 +14,20 @@ module Slack
|
|
14
14
|
#
|
15
15
|
# https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select
|
16
16
|
class MultiConversationsSelect
|
17
|
-
|
17
|
+
include Composition::ConfirmationDialog::Confirmable
|
18
18
|
|
19
|
-
|
19
|
+
TYPE = 'multi_conversations_select'
|
20
20
|
|
21
21
|
def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
|
22
22
|
@placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
|
23
23
|
@action_id = action_id
|
24
24
|
@initial_conversations = initial
|
25
|
-
@confirm = nil
|
26
25
|
@max_selected_items = max_selected_items
|
27
26
|
@filter = nil
|
28
27
|
|
29
28
|
yield(self) if block_given?
|
30
29
|
end
|
31
30
|
|
32
|
-
def confirmation_dialog
|
33
|
-
@confirm = Composition::ConfirmationDialog.new
|
34
|
-
|
35
|
-
yield(@confirm) if block_given?
|
36
|
-
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
31
|
def filter(only: nil,
|
41
32
|
exclude_external_shared_channels: nil,
|
42
33
|
exclude_bot_users: nil)
|
@@ -55,7 +46,7 @@ module Slack
|
|
55
46
|
placeholder: @placeholder.as_json,
|
56
47
|
action_id: @action_id,
|
57
48
|
initial_conversations: @initial_conversations,
|
58
|
-
confirm:
|
49
|
+
confirm: confirm&.as_json,
|
59
50
|
max_selected_items: @max_selected_items,
|
60
51
|
filter: @filter&.as_json
|
61
52
|
}.compact
|
@@ -19,9 +19,9 @@ module Slack
|
|
19
19
|
#
|
20
20
|
# https://api.slack.com/reference/block-kit/block-elements#external_multi_select
|
21
21
|
class MultiExternalSelect
|
22
|
-
|
22
|
+
include Composition::ConfirmationDialog::Confirmable
|
23
23
|
|
24
|
-
|
24
|
+
TYPE = 'multi_external_select'
|
25
25
|
|
26
26
|
def initialize(placeholder:, action_id:,
|
27
27
|
initial: nil, min_query_length: nil, emoji: nil, max_selected_items: nil)
|
@@ -30,20 +30,11 @@ module Slack
|
|
30
30
|
@action_id = action_id
|
31
31
|
@initial_options = initial
|
32
32
|
@min_query_length = min_query_length
|
33
|
-
@confirm = nil
|
34
33
|
@max_selected_items = max_selected_items
|
35
34
|
|
36
35
|
yield(self) if block_given?
|
37
36
|
end
|
38
37
|
|
39
|
-
def confirmation_dialog
|
40
|
-
@confirm = Composition::ConfirmationDialog.new
|
41
|
-
|
42
|
-
yield(@confirm) if block_given?
|
43
|
-
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
38
|
def as_json(*)
|
48
39
|
{
|
49
40
|
type: TYPE,
|
@@ -51,7 +42,7 @@ module Slack
|
|
51
42
|
action_id: @action_id,
|
52
43
|
initial_options: @initial_options&.map(&:as_json),
|
53
44
|
min_query_length: @min_query_length,
|
54
|
-
confirm:
|
45
|
+
confirm: confirm&.as_json,
|
55
46
|
max_selected_items: @max_selected_items
|
56
47
|
}.compact
|
57
48
|
end
|
@@ -13,37 +13,30 @@ module Slack
|
|
13
13
|
#
|
14
14
|
# https://api.slack.com/reference/block-kit/block-elements#static_multi_select
|
15
15
|
class MultiStaticSelect
|
16
|
+
include Composition::ConfirmationDialog::Confirmable
|
17
|
+
|
16
18
|
TYPE = 'multi_static_select'
|
17
19
|
|
18
|
-
attr_accessor :
|
20
|
+
attr_accessor :options, :option_groups
|
19
21
|
|
20
22
|
def initialize(placeholder:, action_id:, emoji: nil, max_selected_items: nil)
|
21
23
|
@placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
|
22
24
|
@action_id = action_id
|
23
|
-
@confirm = nil
|
24
25
|
@max_selected_items = max_selected_items
|
25
26
|
|
26
27
|
@options = nil
|
27
28
|
@option_groups = nil
|
28
|
-
@initial_options = nil
|
29
29
|
|
30
30
|
yield(self) if block_given?
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
@confirm = Composition::ConfirmationDialog.new
|
35
|
-
|
36
|
-
yield(@confirm) if block_given?
|
37
|
-
|
38
|
-
self
|
39
|
-
end
|
40
|
-
|
41
|
-
def option(value:, text:, emoji: nil)
|
33
|
+
def option(value:, text:, initial: false, emoji: nil)
|
42
34
|
@options ||= []
|
43
35
|
@options << Composition::Option.new(
|
44
36
|
value: value,
|
45
37
|
text: text,
|
46
|
-
emoji: emoji
|
38
|
+
emoji: emoji,
|
39
|
+
initial: initial
|
47
40
|
)
|
48
41
|
|
49
42
|
self
|
@@ -60,17 +53,6 @@ module Slack
|
|
60
53
|
self
|
61
54
|
end
|
62
55
|
|
63
|
-
def initial(value:, text:, emoji: nil)
|
64
|
-
@initial_options ||= []
|
65
|
-
@initial_options << Composition::Option.new(
|
66
|
-
value: value,
|
67
|
-
text: text,
|
68
|
-
emoji: emoji
|
69
|
-
)
|
70
|
-
|
71
|
-
self
|
72
|
-
end
|
73
|
-
|
74
56
|
def as_json(*)
|
75
57
|
{
|
76
58
|
type: TYPE,
|
@@ -78,11 +60,21 @@ module Slack
|
|
78
60
|
action_id: @action_id,
|
79
61
|
options: @options&.map(&:as_json),
|
80
62
|
option_groups: @option_groups&.map(&:as_json),
|
81
|
-
initial_options:
|
82
|
-
confirm:
|
63
|
+
initial_options: initial_options&.map(&:as_json),
|
64
|
+
confirm: confirm&.as_json,
|
83
65
|
max_selected_items: @max_selected_items
|
84
66
|
}.compact
|
85
67
|
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def initial_options
|
72
|
+
all_options = options || option_groups&.flat_map(&:options)
|
73
|
+
|
74
|
+
initial = all_options&.select(&:initial?)
|
75
|
+
|
76
|
+
initial&.empty? ? nil : initial
|
77
|
+
end
|
86
78
|
end
|
87
79
|
end
|
88
80
|
end
|