slack_block_kit 0.1.0 → 0.2.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.
@@ -3,14 +3,34 @@
3
3
  module Slack
4
4
  module BlockKit
5
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 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/messaging/block-elements#channel-select
6
15
  class ChannelsSelect
7
16
  TYPE = 'channels_select'
8
17
 
9
- def initialize(placeholder:, action_id:, initial_channel: nil, confirm: nil)
10
- @placeholder = placeholder
18
+ attr_accessor :confirm
19
+
20
+ def initialize(placeholder:, action_id:, initial: nil, emoji: nil)
21
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
11
22
  @action_id = action_id
12
- @initial_conversation = initial_channel
13
- @confirm = confirm
23
+ @initial_channel = initial
24
+
25
+ yield(self) if block_given?
26
+ end
27
+
28
+ def confirmation_dialog
29
+ @confirm = Composition::ConfirmationDialog.new
30
+
31
+ yield(@confirm) if block_given?
32
+
33
+ self
14
34
  end
15
35
 
16
36
  def as_json(*)
@@ -18,9 +38,9 @@ module Slack
18
38
  type: TYPE,
19
39
  placeholder: @placeholder.as_json,
20
40
  action_id: @action_id,
21
- initial_conversation: @initial_channel,
41
+ initial_channel: @initial_channel,
22
42
  confirm: @confirm&.as_json
23
- }
43
+ }.compact
24
44
  end
25
45
  end
26
46
  end
@@ -3,14 +3,35 @@
3
3
  module Slack
4
4
  module BlockKit
5
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 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/messaging/block-elements#conversation-select
6
16
  class ConversationsSelect
7
17
  TYPE = 'conversations_select'
8
18
 
9
- def initialize(placeholder:, action_id:, initial_conversation: nil, confirm: nil)
10
- @placeholder = placeholder
19
+ attr_accessor :confirm
20
+
21
+ def initialize(placeholder:, action_id:, initial: nil, emoji: nil)
22
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
11
23
  @action_id = action_id
12
- @initial_conversation = initial_conversation
13
- @confirm = confirm
24
+ @initial_conversation = initial
25
+
26
+ yield(self) if block_given?
27
+ end
28
+
29
+ def confirmation_dialog
30
+ @confirm = Composition::ConfirmationDialog.new
31
+
32
+ yield(@confirm) if block_given?
33
+
34
+ self
14
35
  end
15
36
 
16
37
  def as_json(*)
@@ -3,14 +3,34 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Element
6
+ # An element which lets users easily select a date from a calendar style
7
+ # UI.
8
+ #
9
+ # Date picker elements can be used inside of section and actions blocks.
10
+ #
11
+ # https://api.slack.com/reference/messaging/block-elements#datepicker
6
12
  class DatePicker
7
13
  TYPE = 'datepicker'
8
14
 
9
- def initialize(action_id:, placeholder: nil, initial_date: nil, confirm: nil)
15
+ def initialize(action_id:, placeholder: nil, initial: nil, emoji: nil)
10
16
  @action_id = action_id
11
- @placeholder = placeholder
12
- @initial_date = initial_date
13
- @confirm = confirm
17
+ @initial_date = initial
18
+ if placeholder
19
+ @placeholder = Composition::PlainText.new(
20
+ text: placeholder,
21
+ emoji: emoji
22
+ )
23
+ end
24
+
25
+ yield(self) if block_given?
26
+ end
27
+
28
+ def confirmation_dialog
29
+ @confirm = Composition::ConfirmationDialog.new
30
+
31
+ yield(@confirm) if block_given?
32
+
33
+ self
14
34
  end
15
35
 
16
36
  def as_json(*)
@@ -3,15 +3,41 @@
3
3
  module Slack
4
4
  module BlockKit
5
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/messaging/block-elements#external-select
6
21
  class ExternalSelect
7
22
  TYPE = 'external_select'
8
23
 
9
- def initialize(placeholder:, action_id:, initial_option: nil, min_query_length: nil, confirm: nil)
10
- @placeholder = placeholder
24
+ attr_accessor :confirm
25
+
26
+ def initialize(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil)
27
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
11
28
  @action_id = action_id
12
- @initial_option = initial_option
29
+ @initial_option = initial
13
30
  @min_query_length = min_query_length
14
- @confirm = confirm
31
+
32
+ yield(self) if block_given?
33
+ end
34
+
35
+ def confirmation_dialog
36
+ @confirm = Composition::ConfirmationDialog.new
37
+
38
+ yield(@confirm) if block_given?
39
+
40
+ self
15
41
  end
16
42
 
17
43
  def as_json(*)
@@ -3,6 +3,11 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Element
6
+ # An element to insert an image - this element can be used in section and
7
+ # context blocks only. If you want a block with only an image in it,
8
+ # you're looking for the image block. (Slack::BlockKit::Layout::Image)
9
+ #
10
+ # https://api.slack.com/reference/messaging/block-elements#image
6
11
  class Image
7
12
  TYPE = 'image'
8
13
 
@@ -3,13 +3,45 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Element
6
+ # This is like a cross between a button and a select menu - when a user
7
+ # clicks on this overflow button, they will be presented with a list of
8
+ # options to choose from. Unlike the select menu, there is no typeahead
9
+ # field, and the button always appears with an ellipsis ("…") rather than
10
+ # customisable text.
11
+ #
12
+ # As such, it is usually used if you want a more compact layout than a
13
+ # select menu, or to supply a list of less visually important actions
14
+ # after a row of buttons.
15
+ #
16
+ # https://api.slack.com/reference/messaging/block-elements#overflow
6
17
  class OverflowMenu
7
18
  TYPE = 'overflow'
8
19
 
9
- def initialize(action_id:, options:, confirm: nil)
20
+ attr_accessor :options, :confirm
21
+
22
+ def initialize(action_id:)
10
23
  @action_id = action_id
11
- @options = options
12
- @confirm = confirm
24
+ @options = []
25
+
26
+ yield(self) if block_given?
27
+ end
28
+
29
+ def option(value:, text:, emoji: nil)
30
+ @options << Composition::Option.new(
31
+ value: value,
32
+ text: text,
33
+ emoji: emoji
34
+ )
35
+
36
+ self
37
+ end
38
+
39
+ def confirmation_dialog
40
+ @confirm = Composition::ConfirmationDialog.new
41
+
42
+ yield(@confirm) if block_given?
43
+
44
+ self
13
45
  end
14
46
 
15
47
  def as_json(*)
@@ -3,16 +3,65 @@
3
3
  module Slack
4
4
  module BlockKit
5
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/messaging/block-elements#static-select
6
15
  class StaticSelect
7
16
  TYPE = 'static_select'
8
17
 
9
- def initialize(placeholder:, action_id:, options:, option_groups:, initial_option: nil, confirm: nil)
10
- @placeholder = placeholder
18
+ attr_accessor :confirm, :options, :option_groups, :initial_option
19
+
20
+ def initialize(placeholder:, action_id:, emoji: nil)
21
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
11
22
  @action_id = action_id
12
- @options = options
13
- @option_groups = option_groups
14
- @initial_option = initial_option
15
- @confirm = confirm
23
+
24
+ yield(self) if block_given?
25
+ end
26
+
27
+ def confirmation_dialog
28
+ @confirm = Composition::ConfirmationDialog.new
29
+
30
+ yield(@confirm) if block_given?
31
+
32
+ self
33
+ end
34
+
35
+ def option(value:, text:, emoji: nil)
36
+ @options ||= []
37
+ @options << Composition::Option.new(
38
+ value: value,
39
+ text: text,
40
+ emoji: emoji
41
+ )
42
+
43
+ self
44
+ end
45
+
46
+ def option_group(label:, emoji: nil)
47
+ option_group = Composition::OptionGroup.new(label: label, emoji: emoji)
48
+
49
+ yield(option_group) if block_given?
50
+
51
+ @option_groups ||= []
52
+ @option_groups << option_group
53
+
54
+ self
55
+ end
56
+
57
+ def initial(value:, text:, emoji: nil)
58
+ @initial_option = Composition::Option.new(
59
+ value: value,
60
+ text: text,
61
+ emoji: emoji
62
+ )
63
+
64
+ self
16
65
  end
17
66
 
18
67
  def as_json(*)
@@ -3,14 +3,34 @@
3
3
  module Slack
4
4
  module BlockKit
5
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 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/messaging/block-elements#users-select
6
15
  class UsersSelect
7
16
  TYPE = 'users_select'
8
17
 
9
- def initialize(placeholder:, action_id:, initial_user: nil, confirm: nil)
10
- @placeholder = placeholder
18
+ attr_accessor :confirm
19
+
20
+ def initialize(placeholder:, action_id:, initial: nil, emoji: nil)
21
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
11
22
  @action_id = action_id
12
- @initial_user = initial_user
13
- @confirm = confirm
23
+ @initial_user = initial
24
+
25
+ yield(self) if block_given?
26
+ end
27
+
28
+ def confirmation_dialog
29
+ @confirm = Composition::ConfirmationDialog.new
30
+
31
+ yield(@confirm) if block_given?
32
+
33
+ self
14
34
  end
15
35
 
16
36
  def as_json(*)
@@ -3,12 +3,125 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Layout
6
+ # A block that is used to hold interactive elements.
7
+ #
8
+ # https://api.slack.com/reference/messaging/blocks#actions
6
9
  class Actions
7
10
  TYPE = 'actions'
8
11
 
9
- def initialize(elements:, block_id: nil)
10
- @elements = elements
12
+ attr_accessor :elements
13
+
14
+ def initialize(block_id: nil)
11
15
  @block_id = block_id
16
+ @elements = []
17
+
18
+ yield(self) if block_given?
19
+ end
20
+
21
+ def button(text:, action_id:, emoji: nil, url: nil, value: nil)
22
+ element = Element::Button.new(
23
+ text: text,
24
+ action_id: action_id,
25
+ emoji: emoji,
26
+ url: url,
27
+ value: value
28
+ )
29
+
30
+ yield(element) if block_given?
31
+
32
+ append(element)
33
+ end
34
+
35
+ def channel_select(placeholder:, action_id:, initial: nil, emoji: nil)
36
+ element = Element::ChannelsSelect.new(
37
+ placeholder: placeholder,
38
+ action_id: action_id,
39
+ initial: initial,
40
+ emoji: emoji
41
+ )
42
+
43
+ yield(element) if block_given?
44
+
45
+ append(element)
46
+ end
47
+
48
+ def converstation_select(placeholder:, action_id:, initial: nil, emoji: nil)
49
+ element = Element::ConversationsSelect.new(
50
+ placeholder: placeholder,
51
+ action_id: action_id,
52
+ initial: initial,
53
+ emoji: emoji
54
+ )
55
+
56
+ yield(element) if block_given?
57
+
58
+ append(element)
59
+ end
60
+
61
+ def date_picker(action_id:, placeholder: nil, initial: nil, emoji: nil)
62
+ element = Element::DatePicker.new(
63
+ placeholder: placeholder,
64
+ action_id: action_id,
65
+ initial: initial,
66
+ emoji: emoji
67
+ )
68
+
69
+ yield(element) if block_given?
70
+
71
+ append(element)
72
+ end
73
+
74
+ def external_select(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil)
75
+ element = Element::ExternalSelect.new(
76
+ placeholder: placeholder,
77
+ action_id: action_id,
78
+ initial: initial,
79
+ min_query_length: min_query_length,
80
+ emoji: emoji
81
+ )
82
+
83
+ yield(element) if block_given?
84
+
85
+ append(element)
86
+ end
87
+
88
+ def overflow_menu(action_id:)
89
+ element = Element::OverflowMenu.new(action_id: action_id)
90
+
91
+ yield(element) if block_given?
92
+
93
+ append(element)
94
+ end
95
+
96
+ def static_select(placeholder:, action_id:, emoji: nil)
97
+ element = Element::StaticSelect.new(
98
+ placeholder: placeholder,
99
+ action_id: action_id,
100
+ emoji: emoji
101
+ )
102
+
103
+ yield(element) if block_given?
104
+
105
+ append(element)
106
+ end
107
+
108
+ def users_select(placeholder:, action_id:, initial: nil, emoji: nil)
109
+ element = Element::UsersSelect.new(
110
+ placeholder: placeholder,
111
+ action_id: action_id,
112
+ emoji: emoji,
113
+ initial: initial
114
+ )
115
+
116
+ yield(element) if block_given?
117
+
118
+ append(element)
119
+ end
120
+
121
+ def append(element)
122
+ @elements << element
123
+
124
+ self
12
125
  end
13
126
 
14
127
  def as_json(*)