slack-ruby-block-kit 0.7.0 → 0.12.0

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +27 -0
  3. data/.rubocop.yml +19 -0
  4. data/.rubocop_todo.yml +10 -0
  5. data/CHANGELOG.md +79 -0
  6. data/Gemfile +3 -1
  7. data/Gemfile.lock +25 -14
  8. data/README.md +1 -1
  9. data/lib/slack/block_kit.rb +44 -2
  10. data/lib/slack/block_kit/composition/confirmation_dialog.rb +16 -0
  11. data/lib/slack/block_kit/composition/conversation_filter.rb +33 -0
  12. data/lib/slack/block_kit/composition/option.rb +6 -1
  13. data/lib/slack/block_kit/composition/option_group.rb +2 -2
  14. data/lib/slack/block_kit/element/button.rb +3 -11
  15. data/lib/slack/block_kit/element/channels_select.rb +3 -11
  16. data/lib/slack/block_kit/element/checkboxes.rb +53 -0
  17. data/lib/slack/block_kit/element/conversations_select.rb +13 -7
  18. data/lib/slack/block_kit/element/date_picker.rb +3 -9
  19. data/lib/slack/block_kit/element/external_select.rb +3 -12
  20. data/lib/slack/block_kit/element/multi_channels_select.rb +5 -14
  21. data/lib/slack/block_kit/element/multi_conversations_select.rb +16 -11
  22. data/lib/slack/block_kit/element/multi_external_select.rb +5 -14
  23. data/lib/slack/block_kit/element/multi_static_select.rb +18 -25
  24. data/lib/slack/block_kit/element/multi_users_select.rb +5 -14
  25. data/lib/slack/block_kit/element/overflow_menu.rb +4 -11
  26. data/lib/slack/block_kit/element/radio_buttons.rb +53 -0
  27. data/lib/slack/block_kit/element/static_select.rb +20 -25
  28. data/lib/slack/block_kit/element/users_select.rb +3 -11
  29. data/lib/slack/block_kit/layout/header.rb +29 -0
  30. data/lib/slack/block_kit/layout/image.rb +1 -4
  31. data/lib/slack/block_kit/layout/section.rb +21 -1
  32. data/lib/slack/block_kit/version.rb +7 -0
  33. data/lib/slack/surfaces/home.rb +35 -0
  34. data/lib/slack/surfaces/message.rb +34 -0
  35. data/lib/slack/surfaces/modal.rb +76 -0
  36. data/slack-ruby-block-kit.gemspec +1 -8
  37. metadata +17 -9
  38. data/.circleci/config.yml +0 -49
@@ -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
- TYPE = 'channels_select'
16
+ include Composition::ConfirmationDialog::Confirmable
17
17
 
18
- attr_accessor :confirm
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: @confirm&.as_json
34
+ confirm: confirm&.as_json
43
35
  }.compact
44
36
  end
45
37
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A checkbox group that allows a user to choose multiple items from
7
+ # a list of possible options.
8
+ #
9
+ # https://api.slack.com/reference/messaging/block-elements#checkboxes
10
+ class Checkboxes
11
+ include Composition::ConfirmationDialog::Confirmable
12
+
13
+ TYPE = 'checkboxes'
14
+
15
+ def initialize(action_id:)
16
+ @action_id = action_id
17
+ @options = []
18
+
19
+ yield(self) if block_given?
20
+ end
21
+
22
+ def option(value:, text:, initial: false, description: nil)
23
+ @options << Composition::Option.new(
24
+ value: value,
25
+ text: text,
26
+ description: description,
27
+ initial: initial
28
+ )
29
+
30
+ self
31
+ end
32
+
33
+ def as_json(*)
34
+ {
35
+ type: TYPE,
36
+ action_id: @action_id,
37
+ options: @options.map(&:as_json),
38
+ initial_options: initial_options&.map(&:as_json),
39
+ confirm: confirm&.as_json
40
+ }.compact
41
+ end
42
+
43
+ private
44
+
45
+ def initial_options
46
+ initial = @options.select(&:initial?)
47
+
48
+ initial.empty? ? nil : initial
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -14,22 +14,27 @@ module Slack
14
14
  #
15
15
  # https://api.slack.com/reference/messaging/block-elements#conversation-select
16
16
  class ConversationsSelect
17
- TYPE = 'conversations_select'
17
+ include Composition::ConfirmationDialog::Confirmable
18
18
 
19
- attr_accessor :confirm
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)
23
23
  @action_id = action_id
24
24
  @initial_conversation = initial
25
+ @filter = nil
25
26
 
26
27
  yield(self) if block_given?
27
28
  end
28
29
 
29
- def confirmation_dialog
30
- @confirm = Composition::ConfirmationDialog.new
31
-
32
- yield(@confirm) if block_given?
30
+ def filter(only: nil,
31
+ exclude_external_shared_channels: nil,
32
+ exclude_bot_users: nil)
33
+ @filter = Composition::ConversationFilter.new(
34
+ only: only,
35
+ exclude_external_shared_channels: exclude_external_shared_channels,
36
+ exclude_bot_users: exclude_bot_users
37
+ )
33
38
 
34
39
  self
35
40
  end
@@ -40,7 +45,8 @@ module Slack
40
45
  placeholder: @placeholder.as_json,
41
46
  action_id: @action_id,
42
47
  initial_conversation: @initial_conversation,
43
- confirm: @confirm&.as_json
48
+ confirm: confirm&.as_json,
49
+ filter: @filter&.as_json
44
50
  }.compact
45
51
  end
46
52
  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: @confirm&.as_json
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
- TYPE = 'external_select'
22
+ include Composition::ConfirmationDialog::Confirmable
23
23
 
24
- attr_accessor :confirm
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: @confirm&.as_json
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
- TYPE = 'multi_channels_select'
16
+ include Composition::ConfirmationDialog::Confirmable
17
17
 
18
- attr_accessor :confirm
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
- @initial_channel = initial
24
- @confirm = nil
23
+ @initial_channels = initial
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
- initial_channel: @initial_channel,
44
- confirm: @confirm&.as_json,
34
+ initial_channels: @initial_channels,
35
+ confirm: confirm&.as_json,
45
36
  max_selected_items: @max_selected_items
46
37
  }.compact
47
38
  end
@@ -14,24 +14,28 @@ module Slack
14
14
  #
15
15
  # https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select
16
16
  class MultiConversationsSelect
17
- TYPE = 'multi_conversations_select'
17
+ include Composition::ConfirmationDialog::Confirmable
18
18
 
19
- attr_accessor :confirm
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
- @initial_conversation = initial
25
- @confirm = nil
24
+ @initial_conversations = initial
26
25
  @max_selected_items = max_selected_items
26
+ @filter = nil
27
27
 
28
28
  yield(self) if block_given?
29
29
  end
30
30
 
31
- def confirmation_dialog
32
- @confirm = Composition::ConfirmationDialog.new
33
-
34
- yield(@confirm) if block_given?
31
+ def filter(only: nil,
32
+ exclude_external_shared_channels: nil,
33
+ exclude_bot_users: nil)
34
+ @filter = Composition::ConversationFilter.new(
35
+ only: only,
36
+ exclude_external_shared_channels: exclude_external_shared_channels,
37
+ exclude_bot_users: exclude_bot_users
38
+ )
35
39
 
36
40
  self
37
41
  end
@@ -41,9 +45,10 @@ module Slack
41
45
  type: TYPE,
42
46
  placeholder: @placeholder.as_json,
43
47
  action_id: @action_id,
44
- initial_conversation: @initial_conversation,
45
- confirm: @confirm&.as_json,
46
- max_selected_items: @max_selected_items
48
+ initial_conversations: @initial_conversations,
49
+ confirm: confirm&.as_json,
50
+ max_selected_items: @max_selected_items,
51
+ filter: @filter&.as_json
47
52
  }.compact
48
53
  end
49
54
  end
@@ -19,39 +19,30 @@ module Slack
19
19
  #
20
20
  # https://api.slack.com/reference/block-kit/block-elements#external_multi_select
21
21
  class MultiExternalSelect
22
- TYPE = 'multi_external_select'
22
+ include Composition::ConfirmationDialog::Confirmable
23
23
 
24
- attr_accessor :confirm
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)
28
28
 
29
29
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
30
30
  @action_id = action_id
31
- @initial_option = initial
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,
50
41
  placeholder: @placeholder.as_json,
51
42
  action_id: @action_id,
52
- initial_option: @initial_option&.as_json,
43
+ initial_options: @initial_options&.map(&:as_json),
53
44
  min_query_length: @min_query_length,
54
- confirm: @confirm&.as_json,
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 :confirm, :options, :option_groups, :initial_option
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_option = nil
29
29
 
30
30
  yield(self) if block_given?
31
31
  end
32
32
 
33
- def confirmation_dialog
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,16 +53,6 @@ module Slack
60
53
  self
61
54
  end
62
55
 
63
- def initial(value:, text:, emoji: nil)
64
- @initial_option = Composition::Option.new(
65
- value: value,
66
- text: text,
67
- emoji: emoji
68
- )
69
-
70
- self
71
- end
72
-
73
56
  def as_json(*)
74
57
  {
75
58
  type: TYPE,
@@ -77,11 +60,21 @@ module Slack
77
60
  action_id: @action_id,
78
61
  options: @options&.map(&:as_json),
79
62
  option_groups: @option_groups&.map(&:as_json),
80
- initial_option: @initial_option&.as_json,
81
- confirm: @confirm&.as_json,
63
+ initial_options: initial_options&.map(&:as_json),
64
+ confirm: confirm&.as_json,
82
65
  max_selected_items: @max_selected_items
83
66
  }.compact
84
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
85
78
  end
86
79
  end
87
80
  end
@@ -13,35 +13,26 @@ module Slack
13
13
  #
14
14
  # https://api.slack.com/reference/block-kit/block-elements#users_multi_select
15
15
  class MultiUsersSelect
16
- TYPE = 'multi_users_select'
16
+ include Composition::ConfirmationDialog::Confirmable
17
17
 
18
- attr_accessor :confirm
18
+ TYPE = 'multi_users_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
- @initial_user = initial
24
- @confirm = nil
23
+ @initial_users = initial
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
- initial_user: @initial_user,
44
- confirm: @confirm&.as_json,
34
+ initial_users: @initial_users,
35
+ confirm: confirm&.as_json,
45
36
  max_selected_items: @max_selected_items
46
37
  }.compact
47
38
  end