slack-ruby-block-kit 0.6.1 → 0.11.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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ci.yml +31 -0
  4. data/.rubocop.yml +46 -1
  5. data/.rubocop_todo.yml +8 -0
  6. data/CHANGELOG.md +56 -0
  7. data/Gemfile +0 -1
  8. data/Gemfile.lock +33 -28
  9. data/lib/slack/block_kit.rb +49 -5
  10. data/lib/slack/block_kit/composition/confirmation_dialog.rb +20 -0
  11. data/lib/slack/block_kit/composition/conversation_filter.rb +33 -0
  12. data/lib/slack/block_kit/composition/option.rb +1 -1
  13. data/lib/slack/block_kit/element/button.rb +3 -11
  14. data/lib/slack/block_kit/element/channels_select.rb +3 -11
  15. data/lib/slack/block_kit/element/checkboxes.rb +55 -0
  16. data/lib/slack/block_kit/element/conversations_select.rb +13 -7
  17. data/lib/slack/block_kit/element/date_picker.rb +3 -9
  18. data/lib/slack/block_kit/element/external_select.rb +3 -11
  19. data/lib/slack/block_kit/element/multi_channels_select.rb +42 -0
  20. data/lib/slack/block_kit/element/multi_conversations_select.rb +57 -0
  21. data/lib/slack/block_kit/element/multi_external_select.rb +52 -0
  22. data/lib/slack/block_kit/element/multi_static_select.rb +82 -0
  23. data/lib/slack/block_kit/element/multi_users_select.rb +42 -0
  24. data/lib/slack/block_kit/element/overflow_menu.rb +4 -10
  25. data/lib/slack/block_kit/element/plain_text_input.rb +1 -1
  26. data/lib/slack/block_kit/element/radio_buttons.rb +48 -0
  27. data/lib/slack/block_kit/element/static_select.rb +4 -10
  28. data/lib/slack/block_kit/element/users_select.rb +3 -11
  29. data/lib/slack/block_kit/layout/context.rb +1 -0
  30. data/lib/slack/block_kit/layout/image.rb +1 -4
  31. data/lib/slack/block_kit/layout/section.rb +29 -1
  32. data/lib/slack/block_kit/layout/section/multi_select_elements.rb +92 -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. metadata +21 -7
  37. 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,55 @@
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
+ @initial_options = []
19
+
20
+ yield(self) if block_given?
21
+ end
22
+
23
+ def option(value:, text:, description: nil)
24
+ @options << Composition::Option.new(
25
+ value: value,
26
+ text: text,
27
+ description: description
28
+ )
29
+
30
+ self
31
+ end
32
+
33
+ def initial(value:, text:, description: nil)
34
+ @initial_options << Composition::Option.new(
35
+ value: value,
36
+ text: text,
37
+ description: description
38
+ )
39
+
40
+ self
41
+ end
42
+
43
+ def as_json(*)
44
+ {
45
+ type: TYPE,
46
+ action_id: @action_id,
47
+ options: @options.map(&:as_json),
48
+ initial_options: @initial_options.any? ? @initial_options.map(&:as_json) : nil,
49
+ confirm: confirm&.as_json
50
+ }.compact
51
+ end
52
+ end
53
+ end
54
+ end
55
+ 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,9 +19,9 @@ 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)
@@ -32,14 +32,6 @@ module Slack
32
32
  yield(self) if block_given?
33
33
  end
34
34
 
35
- def confirmation_dialog
36
- @confirm = Composition::ConfirmationDialog.new
37
-
38
- yield(@confirm) if block_given?
39
-
40
- self
41
- end
42
-
43
35
  def as_json(*)
44
36
  {
45
37
  type: TYPE,
@@ -47,7 +39,7 @@ module Slack
47
39
  action_id: @action_id,
48
40
  initial_option: @initial_option&.as_json,
49
41
  min_query_length: @min_query_length,
50
- confirm: @confirm&.as_json
42
+ confirm: confirm&.as_json
51
43
  }.compact
52
44
  end
53
45
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This multi-select menu will populate its options with a list of public
12
+ # channels visible to the current user in the active workspace.
13
+ #
14
+ # https://api.slack.com/reference/block-kit/block-elements#channel_multi_select
15
+ class MultiChannelsSelect
16
+ include Composition::ConfirmationDialog::Confirmable
17
+
18
+ TYPE = 'multi_channels_select'
19
+
20
+ def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
21
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
22
+ @action_id = action_id
23
+ @initial_channels = initial
24
+ @max_selected_items = max_selected_items
25
+
26
+ yield(self) if block_given?
27
+ end
28
+
29
+ def as_json(*)
30
+ {
31
+ type: TYPE,
32
+ placeholder: @placeholder.as_json,
33
+ action_id: @action_id,
34
+ initial_channels: @initial_channels,
35
+ confirm: confirm&.as_json,
36
+ max_selected_items: @max_selected_items
37
+ }.compact
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This multi-select menu will populate its options with a list of public and
12
+ # private channels, DMs, and MPIMs visible to the current user in the
13
+ # active workspace.
14
+ #
15
+ # https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select
16
+ class MultiConversationsSelect
17
+ include Composition::ConfirmationDialog::Confirmable
18
+
19
+ TYPE = 'multi_conversations_select'
20
+
21
+ def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
22
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
23
+ @action_id = action_id
24
+ @initial_conversations = initial
25
+ @max_selected_items = max_selected_items
26
+ @filter = nil
27
+
28
+ yield(self) if block_given?
29
+ end
30
+
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
+ )
39
+
40
+ self
41
+ end
42
+
43
+ def as_json(*)
44
+ {
45
+ type: TYPE,
46
+ placeholder: @placeholder.as_json,
47
+ action_id: @action_id,
48
+ initial_conversations: @initial_conversations,
49
+ confirm: confirm&.as_json,
50
+ max_selected_items: @max_selected_items,
51
+ filter: @filter&.as_json
52
+ }.compact
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This select menu will load its options from an external data source,
12
+ # allowing for a dynamic list of options.
13
+ #
14
+ # Each time a select menu of this type is opened or the user starts typing
15
+ # in the typeahead field, we'll send a request to your specified URL. Your
16
+ # app should return an HTTP 200 OK response, along with an
17
+ # application/json post body with an object containing either an options
18
+ # array, or an option_groups array.
19
+ #
20
+ # https://api.slack.com/reference/block-kit/block-elements#external_multi_select
21
+ class MultiExternalSelect
22
+ include Composition::ConfirmationDialog::Confirmable
23
+
24
+ TYPE = 'multi_external_select'
25
+
26
+ def initialize(placeholder:, action_id:,
27
+ initial: nil, min_query_length: nil, emoji: nil, max_selected_items: nil)
28
+
29
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
30
+ @action_id = action_id
31
+ @initial_options = initial
32
+ @min_query_length = min_query_length
33
+ @max_selected_items = max_selected_items
34
+
35
+ yield(self) if block_given?
36
+ end
37
+
38
+ def as_json(*)
39
+ {
40
+ type: TYPE,
41
+ placeholder: @placeholder.as_json,
42
+ action_id: @action_id,
43
+ initial_options: @initial_options&.map(&:as_json),
44
+ min_query_length: @min_query_length,
45
+ confirm: confirm&.as_json,
46
+ max_selected_items: @max_selected_items
47
+ }.compact
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This is the simplest form of select menu, with a static list of options
12
+ # passed in when defining the element.
13
+ #
14
+ # https://api.slack.com/reference/block-kit/block-elements#static_multi_select
15
+ class MultiStaticSelect
16
+ include Composition::ConfirmationDialog::Confirmable
17
+
18
+ TYPE = 'multi_static_select'
19
+
20
+ attr_accessor :options, :option_groups, :initial_options
21
+
22
+ def initialize(placeholder:, action_id:, emoji: nil, max_selected_items: nil)
23
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
24
+ @action_id = action_id
25
+ @max_selected_items = max_selected_items
26
+
27
+ @options = nil
28
+ @option_groups = nil
29
+ @initial_options = nil
30
+
31
+ yield(self) if block_given?
32
+ end
33
+
34
+ def option(value:, text:, emoji: nil)
35
+ @options ||= []
36
+ @options << Composition::Option.new(
37
+ value: value,
38
+ text: text,
39
+ emoji: emoji
40
+ )
41
+
42
+ self
43
+ end
44
+
45
+ def option_group(label:, emoji: nil)
46
+ option_group = Composition::OptionGroup.new(label: label, emoji: emoji)
47
+
48
+ yield(option_group) if block_given?
49
+
50
+ @option_groups ||= []
51
+ @option_groups << option_group
52
+
53
+ self
54
+ end
55
+
56
+ def initial(value:, text:, emoji: nil)
57
+ @initial_options ||= []
58
+ @initial_options << Composition::Option.new(
59
+ value: value,
60
+ text: text,
61
+ emoji: emoji
62
+ )
63
+
64
+ self
65
+ end
66
+
67
+ def as_json(*)
68
+ {
69
+ type: TYPE,
70
+ placeholder: @placeholder.as_json,
71
+ action_id: @action_id,
72
+ options: @options&.map(&:as_json),
73
+ option_groups: @option_groups&.map(&:as_json),
74
+ initial_options: @initial_options&.map(&:as_json),
75
+ confirm: confirm&.as_json,
76
+ max_selected_items: @max_selected_items
77
+ }.compact
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This multi-select menu will populate its options with a list of Slack users
12
+ # visible to the current user in the active workspace.
13
+ #
14
+ # https://api.slack.com/reference/block-kit/block-elements#users_multi_select
15
+ class MultiUsersSelect
16
+ include Composition::ConfirmationDialog::Confirmable
17
+
18
+ TYPE = 'multi_users_select'
19
+
20
+ def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
21
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
22
+ @action_id = action_id
23
+ @initial_users = initial
24
+ @max_selected_items = max_selected_items
25
+
26
+ yield(self) if block_given?
27
+ end
28
+
29
+ def as_json(*)
30
+ {
31
+ type: TYPE,
32
+ placeholder: @placeholder.as_json,
33
+ action_id: @action_id,
34
+ initial_users: @initial_users,
35
+ confirm: confirm&.as_json,
36
+ max_selected_items: @max_selected_items
37
+ }.compact
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end