slack_valid_block_kit 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0480d87bdb716159283ac0c8293786bcc7049ae0359688051f7012c1d777987d'
4
+ data.tar.gz: c347150c2d148e79246849e997075746f84a2d841bce59d3fd5f045a3c31cc56
5
+ SHA512:
6
+ metadata.gz: ff0d1441182f2ca00c9d6baa1e0652bdc4c12be126c6f6586bccc46cb91f8245b92e6f6b63319877e50352b65fc0ed40be4ac3fdf043de363cc5ffbeb733a504
7
+ data.tar.gz: 722d5e4da93846cda12e90d7a21c265b9485d66c94ca602f50054b1061baf45c8d1dbcd99ca2637aec4199d90de7821f65e85566402f0ca6e0e46797c6513040
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.8
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at masayuki-ioki@cookpad.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in slack_valid_block_kit.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 masayuki-ioki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # SlackValidBlockKit
2
+
3
+ A tool for building Slack Block Kit with validation.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'slack_valid_block_kit'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install slack_valid_block_kit
20
+
21
+ ## Usage
22
+
23
+ - [surfaces.rb](https://github.com/kikaineko/slack_valid_block_kit/blob/main/lib/slack_valid_block_kit/builder/surfaces.rb) contains the [View objects](https://api.slack.com/reference/surfaces/views)
24
+ - [layouts.rb](https://github.com/kikaineko/slack_valid_block_kit/blob/main/lib/slack_valid_block_kit/builder/layouts.rb) contains the [Layout blocks](https://api.slack.com/reference/messaging/blocks)
25
+ - [elements.rb](https://github.com/kikaineko/slack_valid_block_kit/blob/main/lib/slack_valid_block_kit/builder/elements.rb) contains the [Block elements](https://api.slack.com/reference/messaging/block-elements)
26
+ - [compositions.rb](https://github.com/kikaineko/slack_valid_block_kit/blob/main/lib/slack_valid_block_kit/builder/compositions.rb) contains the [Message composition objects](https://api.slack.com/reference/messaging/composition-objects)
27
+
28
+
29
+ You can build views by `SlackValidBlockKit.build` or `SlackValidBlockKit.blocks`.
30
+
31
+ Both methods run validation your views automatically.
32
+
33
+ ```ruby
34
+ # Build modal with validation
35
+ modal = SlackValidBlockKit.build do |b|
36
+ b.modal(...)
37
+ end
38
+
39
+ # Build blocks with validation
40
+ blocks = SlackValidBlockKit.blocks do |b|
41
+ [...]
42
+ end
43
+ ```
44
+
45
+ If you want to skip validations, you write as follows.
46
+
47
+ ```ruby
48
+ # Build modal without validation
49
+ modal = SlackValidBlockKit.build(validate: false) do |b|
50
+ b.modal(...)
51
+ end
52
+
53
+ # Build blocks without validation
54
+ blocks = SlackValidBlockKit.blocks(validate: false) do |b|
55
+ [...]
56
+ end
57
+ ```
58
+
59
+ or you can set to skip validations as config
60
+ ```ruby
61
+ SlackValidBlockKit::Config.skip_validation = true
62
+ ```
63
+
64
+ For example, when you ride on Rails, you can set in `config/initializers/slack_valid_block_kit.rb`.
65
+
66
+ ```ruby
67
+ SlackValidBlockKit::Config.skip_validation = Rails.env.production?
68
+ ```
69
+
70
+ You can just use validations.
71
+
72
+ ```ruby
73
+ modal = ... # create a modal hash without SlackValidBlockKit
74
+
75
+ SlackValidBlockKit.validate!(modal) # raise an exception with the invalid input
76
+
77
+
78
+ blocks = ... # create a blocks array without SlackValidBlockKit
79
+
80
+ SlackValidBlockKit.validate_blocks!(blocks) # raise an exception with the invalid input
81
+ ```
82
+
83
+ ## Examples
84
+
85
+ Modal example with validation
86
+
87
+ ```ruby
88
+ require 'slack_valid_block_kit'
89
+ require 'json'
90
+
91
+ modal = SlackValidBlockKit.build do |b|
92
+ b.modal(
93
+ title: b.plain_text(text: "Modal title"),
94
+ blocks: [
95
+ b.section(
96
+ text: b.mrkdwn(text: "It's Block Kit...but _in a modal_"),
97
+ block_id: "section1",
98
+ accessory: b.button(
99
+ text: b.plain_text(text: "Click me"),
100
+ action_id: "button_abc",
101
+ value: "Button value",
102
+ style: "danger"
103
+ )
104
+ )
105
+ ],
106
+ close: b.plain_text(text: "Cancel"),
107
+ submit: b.plain_text(text: "Save"),
108
+ private_metadata: "Shhhhhhhh",
109
+ callback_id: "view_identifier_12"
110
+ )
111
+ end
112
+
113
+ puts modal.to_json
114
+ ```
115
+
116
+ You will get this.
117
+ ![modal example](https://user-images.githubusercontent.com/724270/167277875-c1e6627f-e59d-485f-b574-d5797c954f36.png)
118
+
119
+ You can get a just `blocks` array (with validation).
120
+
121
+ ```ruby
122
+ require 'slack_valid_block_kit'
123
+ require 'json'
124
+
125
+ blocks = SlackValidBlockKit.blocks do |b|
126
+ [
127
+ b.divider,
128
+ b.section(
129
+ text: b.mrkdwn(text: "*<fakeLink.toHotelPage.com|Windsor Court Hotel>*\n★★★★★\n$340 per night\nRated: 9.4 - Excellent"),
130
+ accessory: b.image(
131
+ image_url: "https://api.slack.com/img/blocks/bkb_template_images/tripAgent_1.png",
132
+ alt_text: "Windsor Court Hotel thumbnail"
133
+ )
134
+ ),
135
+ b.context(
136
+ elements: [
137
+ b.image(
138
+ image_url: "https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png",
139
+ alt_text: "Location Pin Icon"
140
+ ),
141
+ b.plain_text(text: "Location: Central Business District", emoji: true)
142
+ ]
143
+ )
144
+ ]
145
+ end
146
+
147
+ puts blocks.to_json
148
+ ```
149
+
150
+ You will get this.
151
+ ![message example](https://user-images.githubusercontent.com/724270/167278001-2235d8b6-9d4b-47dd-b5ba-13880383f89b.png)
152
+
153
+ ##
154
+
155
+ ## Development
156
+
157
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
158
+
159
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
160
+
161
+ ## Contributing
162
+
163
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slack_valid_block_kit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
164
+
165
+ ## License
166
+
167
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
168
+
169
+ ## Code of Conduct
170
+
171
+ Everyone interacting in the SlackValidBlockKit project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/slack_valid_block_kit/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "slack_valid_block_kit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,59 @@
1
+ module SlackValidBlockKit
2
+ module Builder
3
+ module Compositions
4
+ def plain_text(text:, emoji: nil)
5
+ hash = { type: 'plain_text' }
6
+ hash[:text] = text
7
+ hash[:emoji] = emoji unless emoji.nil?
8
+ hash
9
+ end
10
+
11
+ def mrkdwn(text:, verbatim: nil)
12
+ hash = { type: 'mrkdwn' }
13
+ hash[:text] = text
14
+ hash[:verbatim] = verbatim unless verbatim.nil?
15
+ hash
16
+ end
17
+
18
+ def confirmation(title:, text:, confirm:, deny:, style: nil)
19
+ hash = {}
20
+ hash[:title] = title
21
+ hash[:text] = text
22
+ hash[:confirm] = confirm
23
+ hash[:deny] = deny
24
+ hash[:style] = style unless style.nil?
25
+ hash
26
+ end
27
+
28
+ def option(text:, value:, description: nil, url: nil)
29
+ hash = {}
30
+ hash[:text] = text
31
+ hash[:value] = value
32
+ hash[:description] = description unless description.nil?
33
+ hash[:url] = url unless url.nil?
34
+ hash
35
+ end
36
+
37
+ def option_group(label:, options:)
38
+ hash = {}
39
+ hash[:label] = label
40
+ hash[:options] = options
41
+ hash
42
+ end
43
+
44
+ def dispatch_action_configuration(trigger_actions_on: nil)
45
+ hash = {}
46
+ hash[:trigger_actions_on] = trigger_actions_on unless trigger_actions_on.nil?
47
+ hash
48
+ end
49
+
50
+ def filter(include: nil, exclude_external_shared_channels: nil, exclude_bot_users: nil)
51
+ hash = {}
52
+ hash[:include] = include unless include.nil?
53
+ hash[:exclude_external_shared_channels] = exclude_external_shared_channels unless exclude_external_shared_channels.nil?
54
+ hash[:exclude_bot_users] = exclude_bot_users unless exclude_bot_users.nil?
55
+ hash
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,202 @@
1
+ module SlackValidBlockKit
2
+ module Builder
3
+ module Elements
4
+ def button(text:, action_id:, url: nil, value: nil, style: nil, confirm: nil, accessibility_label: nil)
5
+ hash = { type: 'button' }
6
+ hash[:text] = text
7
+ hash[:action_id] = action_id
8
+ hash[:url] = url unless url.nil?
9
+ hash[:value] = value unless value.nil?
10
+ hash[:style] = style unless style.nil?
11
+ hash[:confirm] = confirm unless confirm.nil?
12
+ hash[:accessibility_label] = accessibility_label unless accessibility_label.nil?
13
+ hash
14
+ end
15
+
16
+ def checkboxes(action_id:, options:, initial_options: nil, confirm: nil, focus_on_load: nil)
17
+ hash = { type: 'checkboxes' }
18
+ hash[:action_id] = action_id
19
+ hash[:options] = options
20
+ hash[:initial_options] = initial_options unless initial_options.nil?
21
+ hash[:confirm] = confirm unless confirm.nil?
22
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
23
+ hash
24
+ end
25
+
26
+ def datepicker(action_id:, placeholder: nil, initial_date: nil, confirm: nil, focus_on_load: nil)
27
+ hash = { type: 'datepicker' }
28
+ hash[:action_id] = action_id
29
+ hash[:placeholder] = placeholder unless placeholder.nil?
30
+ hash[:initial_date] = initial_date unless initial_date.nil?
31
+ hash[:confirm] = confirm unless confirm.nil?
32
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
33
+ hash
34
+ end
35
+
36
+ def image(image_url:, alt_text:)
37
+ hash = { type: 'image' }
38
+ hash[:image_url] = image_url
39
+ hash[:alt_text] = alt_text
40
+ hash
41
+ end
42
+
43
+ def multi_static_select(placeholder:, action_id:, options:, option_groups: nil, initial_options: nil, confirm: nil, max_selected_items: nil, focus_on_load: nil)
44
+ hash = { type: 'multi_static_select' }
45
+ hash[:placeholder] = placeholder
46
+ hash[:action_id] = action_id
47
+ hash[:options] = options
48
+ hash[:option_groups] = option_groups unless option_groups.nil?
49
+ hash[:initial_options] = initial_options unless initial_options.nil?
50
+ hash[:confirm] = confirm unless confirm.nil?
51
+ hash[:max_selected_items] = max_selected_items unless max_selected_items.nil?
52
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
53
+ hash
54
+ end
55
+
56
+ def multi_external_select(placeholder:, action_id:, min_query_length: nil, initial_options: nil, confirm: nil, max_selected_items: nil, focus_on_load: nil)
57
+ hash = { type: 'multi_external_select' }
58
+ hash[:placeholder] = placeholder
59
+ hash[:action_id] = action_id
60
+ hash[:min_query_length] = min_query_length unless min_query_length.nil?
61
+ hash[:initial_options] = initial_options unless initial_options.nil?
62
+ hash[:confirm] = confirm unless confirm.nil?
63
+ hash[:max_selected_items] = max_selected_items unless max_selected_items.nil?
64
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
65
+ hash
66
+ end
67
+
68
+ def multi_users_select(placeholder:, action_id:, initial_users: nil, confirm: nil, max_selected_items: nil, focus_on_load: nil)
69
+ hash = { type: 'multi_users_select' }
70
+ hash[:placeholder] = placeholder
71
+ hash[:action_id] = action_id
72
+ hash[:initial_users] = initial_users unless initial_users.nil?
73
+ hash[:confirm] = confirm unless confirm.nil?
74
+ hash[:max_selected_items] = max_selected_items unless max_selected_items.nil?
75
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
76
+ hash
77
+ end
78
+
79
+ def multi_conversations_select(placeholder:, action_id:, initial_conversations: nil, default_to_current_conversation: nil, confirm: nil, max_selected_items: nil, filter: nil, focus_on_load: nil)
80
+ hash = { type: 'multi_conversations_select' }
81
+ hash[:placeholder] = placeholder
82
+ hash[:action_id] = action_id
83
+ hash[:initial_conversations] = initial_conversations unless initial_conversations.nil?
84
+ hash[:default_to_current_conversation] = default_to_current_conversation unless default_to_current_conversation.nil?
85
+ hash[:confirm] = confirm unless confirm.nil?
86
+ hash[:max_selected_items] = max_selected_items unless max_selected_items.nil?
87
+ hash[:filter] = filter unless filter.nil?
88
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
89
+ hash
90
+ end
91
+
92
+ def multi_channels_select(placeholder:, action_id:, initial_channels: nil, confirm: nil, max_selected_items: nil, focus_on_load: nil)
93
+ hash = { type: 'multi_channels_select' }
94
+ hash[:placeholder] = placeholder
95
+ hash[:action_id] = action_id
96
+ hash[:initial_channels] = initial_channels unless initial_channels.nil?
97
+ hash[:confirm] = confirm unless confirm.nil?
98
+ hash[:max_selected_items] = max_selected_items unless max_selected_items.nil?
99
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
100
+ hash
101
+ end
102
+
103
+ def overflow(options:, action_id:, confirm: nil)
104
+ hash = { type: 'overflow' }
105
+ hash[:options] = options
106
+ hash[:action_id] = action_id
107
+ hash[:confirm] = confirm unless confirm.nil?
108
+ hash
109
+ end
110
+
111
+ def plain_text_input(action_id:, placeholder: nil, initial_value: nil, multiline: nil, min_length: nil, max_length: nil, dispatch_action_config: nil, focus_on_load: nil)
112
+ hash = { type: 'plain_text_input' }
113
+ hash[:action_id] = action_id
114
+ hash[:placeholder] = placeholder unless placeholder.nil?
115
+ hash[:initial_value] = initial_value unless initial_value.nil?
116
+ hash[:multiline] = multiline unless multiline.nil?
117
+ hash[:min_length] = min_length unless min_length.nil?
118
+ hash[:max_length] = max_length unless max_length.nil?
119
+ hash[:dispatch_action_config] = dispatch_action_config unless dispatch_action_config.nil?
120
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
121
+ hash
122
+ end
123
+
124
+ def radio_buttons(options:, action_id:, initial_option: nil, confirm: nil, focus_on_load: nil)
125
+ hash = { type: 'radio_buttons' }
126
+ hash[:options] = options
127
+ hash[:action_id] = action_id
128
+ hash[:initial_option] = initial_option unless initial_option.nil?
129
+ hash[:confirm] = confirm unless confirm.nil?
130
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
131
+ hash
132
+ end
133
+
134
+ def static_select(placeholder:, action_id:, options:, option_groups: nil, initial_option: nil, confirm: nil, focus_on_load: nil)
135
+ hash = { type: 'static_select' }
136
+ hash[:placeholder] = placeholder
137
+ hash[:action_id] = action_id
138
+ hash[:options] = options
139
+ hash[:option_groups] = option_groups unless option_groups.nil?
140
+ hash[:initial_option] = initial_option unless initial_option.nil?
141
+ hash[:confirm] = confirm unless confirm.nil?
142
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
143
+ hash
144
+ end
145
+
146
+ def external_select(placeholder:, action_id:, min_query_length: nil, initial_option: nil, confirm: nil, focus_on_load: nil)
147
+ hash = { type: 'external_select' }
148
+ hash[:placeholder] = placeholder
149
+ hash[:action_id] = action_id
150
+ hash[:min_query_length] = min_query_length unless min_query_length.nil?
151
+ hash[:initial_option] = initial_option unless initial_option.nil?
152
+ hash[:confirm] = confirm unless confirm.nil?
153
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
154
+ hash
155
+ end
156
+
157
+ def users_select(placeholder:, action_id:, initial_user: nil, confirm: nil, focus_on_load: nil)
158
+ hash = { type: 'users_select' }
159
+ hash[:placeholder] = placeholder
160
+ hash[:action_id] = action_id
161
+ hash[:initial_user] = initial_user unless initial_user.nil?
162
+ hash[:confirm] = confirm unless confirm.nil?
163
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
164
+ hash
165
+ end
166
+
167
+ def conversations_select(placeholder:, action_id:, initial_conversation: nil, default_to_current_conversation: nil, confirm: nil, response_url_enabled: nil, filter: nil, focus_on_load: nil)
168
+ hash = { type: 'conversations_select' }
169
+ hash[:placeholder] = placeholder
170
+ hash[:action_id] = action_id
171
+ hash[:initial_conversation] = initial_conversation unless initial_conversation.nil?
172
+ hash[:default_to_current_conversation] = default_to_current_conversation unless default_to_current_conversation.nil?
173
+ hash[:confirm] = confirm unless confirm.nil?
174
+ hash[:response_url_enabled] = response_url_enabled unless response_url_enabled.nil?
175
+ hash[:filter] = filter unless filter.nil?
176
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
177
+ hash
178
+ end
179
+
180
+ def channels_select(placeholder:, action_id:, initial_channel: nil, confirm: nil, response_url_enabled: nil, focus_on_load: nil)
181
+ hash = { type: 'channels_select' }
182
+ hash[:placeholder] = placeholder
183
+ hash[:action_id] = action_id
184
+ hash[:initial_channel] = initial_channel unless initial_channel.nil?
185
+ hash[:confirm] = confirm unless confirm.nil?
186
+ hash[:response_url_enabled] = response_url_enabled unless response_url_enabled.nil?
187
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
188
+ hash
189
+ end
190
+
191
+ def timepicker(action_id:, placeholder: nil, initial_time: nil, confirm: nil, focus_on_load: nil)
192
+ hash = { type: 'timepicker' }
193
+ hash[:action_id] = action_id
194
+ hash[:placeholder] = placeholder unless placeholder.nil?
195
+ hash[:initial_time] = initial_time unless initial_time.nil?
196
+ hash[:confirm] = confirm unless confirm.nil?
197
+ hash[:focus_on_load] = focus_on_load unless focus_on_load.nil?
198
+ hash
199
+ end
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,69 @@
1
+ module SlackValidBlockKit
2
+ module Builder
3
+ module Layouts
4
+ def actions(elements:, block_id: nil)
5
+ hash = { type: 'actions' }
6
+ hash[:elements] = elements
7
+ hash[:block_id] = block_id unless block_id.nil?
8
+ hash
9
+ end
10
+
11
+ def context(elements:, block_id: nil)
12
+ hash = { type: 'context' }
13
+ hash[:elements] = elements
14
+ hash[:block_id] = block_id unless block_id.nil?
15
+ hash
16
+ end
17
+
18
+ def divider(block_id: nil)
19
+ hash = { type: 'divider' }
20
+ hash[:block_id] = block_id unless block_id.nil?
21
+ hash
22
+ end
23
+
24
+ def file(elements:, source:, block_id: nil)
25
+ hash = { type: 'file' }
26
+ hash[:elements] = elements
27
+ hash[:source] = source
28
+ hash[:block_id] = block_id unless block_id.nil?
29
+ hash
30
+ end
31
+
32
+ def header(text:, block_id: nil)
33
+ hash = { type: 'header' }
34
+ hash[:text] = text
35
+ hash[:block_id] = block_id unless block_id.nil?
36
+ hash
37
+ end
38
+
39
+ def image(image_url:, alt_text:, title: nil, block_id: nil)
40
+ hash = { type: 'image' }
41
+ hash[:image_url] = image_url
42
+ hash[:alt_text] = alt_text
43
+ hash[:title] = title unless title.nil?
44
+ hash[:block_id] = block_id unless block_id.nil?
45
+ hash
46
+ end
47
+
48
+ def input(label:, element:, dispatch_action: nil, block_id: nil, hint: nil, optional: nil)
49
+ hash = { type: 'input' }
50
+ hash[:label] = label
51
+ hash[:element] = element
52
+ hash[:dispatch_action] = dispatch_action unless dispatch_action.nil?
53
+ hash[:block_id] = block_id unless block_id.nil?
54
+ hash[:hint] = hint unless hint.nil?
55
+ hash[:optional] = optional unless optional.nil?
56
+ hash
57
+ end
58
+
59
+ def section(text: nil, block_id: nil, fields: nil, accessory: nil)
60
+ hash = { type: 'section' }
61
+ hash[:text] = text unless text.nil?
62
+ hash[:block_id] = block_id unless block_id.nil?
63
+ hash[:fields] = fields unless fields.nil?
64
+ hash[:accessory] = accessory unless accessory.nil?
65
+ hash
66
+ end
67
+ end
68
+ end
69
+ end