grape-slack-bot 2.1.2 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45d672bb2de61c8d0d1335a0ddf37c9242dc97dd6db90ba630a1d70d7330436c
4
- data.tar.gz: a42ebdc015514c1e66a38511d54ce21e718be36161d14ead247859e09bffbe87
3
+ metadata.gz: e439c9df6bc7266e9b6bc96044291cd195ca2bc803ceec0ccd908ba1f694349a
4
+ data.tar.gz: bd637145592b5e66e26d4d23711baf7e5c2b4f6eb2d5531003bd0a09253184e0
5
5
  SHA512:
6
- metadata.gz: 1e41c14e09be9c8687b6653ea29a102586e3fb2750f68533dc63aef9a914f8d4aa818e2af8d8a850f9b9ecaeefff1268d5315fa3f5b42405b9df7c0311f19968
7
- data.tar.gz: c1e26e64aa95b0ff1ceef088a171888e508348e3afca8fb865eca5071841c052178daa015ce19f6ffee7a70850597fdf276f843ca78b4698c8cd7640afeff766
6
+ metadata.gz: 89d89feb6e813740c0ad667ce118089dbe147971b683acc256f587ebcd1a6d3bbf67810bfda92226652597d8c284abc9c80eb809e24d27b9acd11fc1beb63bab
7
+ data.tar.gz: e3595568199fa5ed01280157b20f2418a5ec35c13d1e1483d872d9120e34ddd52e26c87de7fdb463ac1a31392d406584834f11bc59293e92946bbfcf58620586
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.0.0 (2026-11-18)
4
+
5
+ - Define modular Slack handlers with `SlackBot::Schema` and register them alongside existing Config handlers (RFC-0002).
6
+ - Accept Slack shortcuts, message actions, view closures, and POST requests to the Options Load URL. Keep GET options requests available.
7
+ - Declare modal and message replies with `respond_with`, including submission validation, modal pushes, and `response_url` replies.
8
+ - Add `ApiClient#views_push` and `ApiClient#response_url_post`.
9
+ - Read the interaction payload and workspace from the signed POST body.
10
+ - Keep request and callback contents out of development logs.
11
+
12
+ ## 2.1.3 (2026-11-07)
13
+
14
+ - Memoize parsed JSON in `SlackBot::ApiResponse#data` so repeated reads do not re-parse the response body
15
+ - Encode Slack API request bodies with `JSON.generate` instead of ActiveSupport `Hash#to_json`
16
+ - Verify Slack signatures with `HMAC.digest` and binary `secure_compare`; cache the request body for the verify pass
17
+ - Keep `ApiResponse` hot-path shortcuts always on; drop `SlackBot::PressureOpts` / `SLACK_PRESSURE_*` feature flags
18
+ - Return HTTP 401 when Slack request signature verification fails
19
+ - Clamp a negative `Retry-After` value to zero before the bounded retry
20
+ - Fail closed when release confirmation input reaches EOF
21
+ - Require a matching `CHANGELOG.md` version heading before publish
22
+ - Give the test workflow read-only `contents` permission
23
+
3
24
  ## 2.1.2 (2026-09-15)
4
25
 
5
26
  - Allow grape 4.x by expanding the runtime dependency to `< 5.0`
data/README.md CHANGED
@@ -105,6 +105,158 @@ In routes file `config/routes.rb` mount the API:
105
105
  mount SlackBotApi => "/api/slack"
106
106
  ```
107
107
 
108
+ ## Slack Schema
109
+
110
+ Use `SlackBot::Schema` to define handlers in separate classes and share
111
+ registrations across bots. Install it with `use` inside `Config.configure`.
112
+ Existing Config registrations and handlers using `call` can coexist with Schema
113
+ handlers.
114
+
115
+ ```ruby
116
+ class StartInput < SlackBot::Schema::InputObject
117
+ argument :name, String, required: true
118
+ argument :rounds, Integer, default: 1
119
+ end
120
+
121
+ class StartGame < SlackBot::Schema::SlashCommand
122
+ input StartInput
123
+
124
+ def resolve(name:, rounds:)
125
+ {response_type: "ephemeral", text: "#{name}: #{rounds} rounds"}
126
+ end
127
+ end
128
+
129
+ class GameMenu < SlackBot::Schema::SlashCommand
130
+ def resolve
131
+ {response_type: "ephemeral", text: "Try /game start name=quiz&rounds=3"}
132
+ end
133
+ end
134
+
135
+ class GameCommands < SlackBot::Schema::SlashCommandGroup
136
+ default_command GameMenu
137
+ command :start, StartGame
138
+ end
139
+
140
+ class GameSchema < SlackBot::Schema
141
+ slash_command :game, GameCommands
142
+ end
143
+
144
+ class BotSchema < SlackBot::Schema
145
+ mount GameSchema
146
+ end
147
+
148
+ SlackBot::Config.configure do
149
+ use BotSchema
150
+ end
151
+ ```
152
+
153
+ Input objects read the command's existing query-string format. Arguments
154
+ can use `String`, `Integer`, `Float`, or a callable that receives the raw
155
+ value. Declare `required: true` for required arguments and `default:` for a
156
+ typed default. Slash handlers inherit the existing user, workspace, and
157
+ direct-message checks.
158
+
159
+ ### Supported Slack HTTP requests
160
+
161
+ ```mermaid
162
+ flowchart TB
163
+ Commands["POST commands/:url_token"] --> Slash["Slash command"]
164
+ Events["POST events"] --> Event["event_callback / url_verification"]
165
+ Interactions["POST interactions"] --> Blocks["block_actions"]
166
+ Interactions --> Submission["view_submission"]
167
+ Interactions --> Closed["view_closed"]
168
+ Interactions --> Shortcut["shortcut"]
169
+ Interactions --> Message["message_actions / message_action"]
170
+ Options["POST menu_options"] --> Suggestion["block_suggestion"]
171
+ Legacy["GET menu_options"] --> Suggestion
172
+ ```
173
+
174
+ | Payload | Registration | Schema handler |
175
+ | --- | --- | --- |
176
+ | Slash command | `slash_command :url_token, Handler` | `SlashCommand` or `SlashCommandGroup` |
177
+ | `event_callback` | `event :type, Handler` | `Event` |
178
+ | `url_verification` | Handled by the Events endpoint | |
179
+ | `block_actions` | `block_actions :action_id, Handler` for messages and unscoped App Home views. Declare `block_actions Handler` on a scoped view owner. | `BlockActions` |
180
+ | `view_submission` | Declare `view_submission Handler` on the view owner | `ViewSubmission` |
181
+ | `view_closed` | Declare `view_closed Handler` on the owner or register `view_closed :callback_id, Handler` for externally opened views | `ViewClosed` |
182
+ | `shortcut` | `shortcut :callback_id, Handler` | `Shortcut` |
183
+ | `message_action` or `message_actions` | `message_action :callback_id, Handler` | `MessageAction` |
184
+ | `block_suggestion` | `block_suggestion :action_id, Handler` or `options :action_id, Handler` | `Options` |
185
+
186
+ Set Slack's **Options Load URL** to the existing mounted `/menu_options`
187
+ endpoint. Slack sends a form-encoded POST with a `payload` containing
188
+ `type: "block_suggestion"`, `action_id`, and `value`. Return `{options: [...]}`
189
+ or `{option_groups: [...]}`. Existing `menu_options` registrations continue
190
+ to accept GET calls with `action_id` and `value` in the query string.
191
+ See the [Slack interaction payload reference](https://docs.slack.dev/reference/interaction-payloads/)
192
+ and [Options Load payload reference](https://docs.slack.dev/reference/interaction-payloads/block_suggestion-payload/).
193
+
194
+ ### Actions and responses
195
+
196
+ Declare `view ViewClass` on a handler to render views. A slash command,
197
+ event, shortcut, or block action can declare the view's `block_actions`,
198
+ `view_submission`, and `view_closed` handlers. Set `notify_on_close: true`
199
+ in a modal to receive a close payload. Configure `callback_storage` and
200
+ `user_session_resolver` for scoped views, and declare named owner classes so
201
+ their callbacks can route after a process restart.
202
+
203
+ ```ruby
204
+ class EditSubmission < SlackBot::Schema::ViewSubmission
205
+ respond_with response_action: :clear
206
+
207
+ def resolve
208
+ name = view_state(:name_block, :name_input)
209
+ return {errors: {name_block: "Enter a name"}} if name.to_s.empty?
210
+
211
+ nil
212
+ end
213
+ end
214
+
215
+ class EditShortcut < SlackBot::Schema::Shortcut
216
+ view TicketView
217
+ view_submission EditSubmission
218
+ respond_with open_modal: :edit_modal
219
+ end
220
+ ```
221
+
222
+ | Declaration | Result |
223
+ | --- | --- |
224
+ | `respond_with open_modal: :edit_modal` | Call `views.open` using the trigger |
225
+ | `respond_with update_modal: :edit_modal` | Call `views.update` using the current view ID and its hash when supplied |
226
+ | `respond_with push_modal: :details_modal` | Call `views.push` using the trigger |
227
+ | `respond_with publish_view: :home` | Call `views.publish` for the Slack user |
228
+ | `respond_with response_action: :update, view: :edit_modal` | Return replacement view JSON on submission |
229
+ | `respond_with response_action: :push, view: :details_modal` | Return a new view on submission |
230
+ | `respond_with response_action: :clear` | Clear the modal stack on submission |
231
+ | `respond_with response_action: :errors` | Use the resolver's `{errors: {block_id => message}}` for field errors |
232
+ | `respond_with response_url: :ephemeral, text: "Saved", blocks: :confirmation` | Send text and rendered message blocks to Slack |
233
+ | `respond_with response_url: :in_channel, replace_original: true, text: "Saved"` | Replace the source message |
234
+ | `respond_with delete_original: true` | Delete the source message |
235
+ | `respond_with :ack` or `respond_with :none` | Acknowledge, or let the resolver return its own response |
236
+
237
+ A hash from `resolve` overrides a declaration. In a submission, an
238
+ `errors:` hash becomes a Slack validation response. Return `:halt` to
239
+ acknowledge immediately and skip the declared response. A submission with
240
+ one `response_urls` entry can use it for declarative replies. For multiple
241
+ entries, choose the destination in `resolve` and use
242
+ `SlackBot::ApiClient.response_url_post(url, **message)`. The instance
243
+ method of the same name is also available.
244
+
245
+ On a `BlockActions` handler, `action :pick, args: {user_id: :selected_user}`
246
+ calls `pick(user_id:)` when Slack sends that action ID. Use `with: :method`
247
+ to select another method, or `with: ServiceClass` to instantiate it with
248
+ the extracted keyword arguments and call it. Extractors can use Slack
249
+ field names, `:selected_option_value`, `:selected_option_values`, or a
250
+ callable that receives the action hash. Override `resolve` to control
251
+ dispatch explicitly and call `super` to run the declared actions.
252
+ On a submission, `view_state` returns the full state map, one block's
253
+ state, or the submitted value at a block and action ID.
254
+
255
+ See [Slack acknowledgements and message responses](https://docs.slack.dev/interactivity/handling-user-interaction/)
256
+ and [Slack modals](https://docs.slack.dev/surfaces/modals/) for response
257
+ mechanisms and timing. See [RFC-0002](rfcs/0002-slack-schema.md) for the
258
+ Schema contract and scope.
259
+
108
260
  ## Concepts
109
261
 
110
262
  ### Slash command
@@ -206,7 +358,7 @@ features:
206
358
  always_online: true
207
359
  slash_commands:
208
360
  - command: /game
209
- url: https://example.com/api/slack/commands/game
361
+ url: https://bot.rails.fi/api/slack/commands/game
210
362
  description: The game
211
363
  should_escape: false
212
364
  oauth_config:
@@ -229,7 +381,7 @@ oauth_config:
229
381
  - commands
230
382
  settings:
231
383
  event_subscriptions:
232
- request_url: https://example.com/api/slack/events
384
+ request_url: https://bot.rails.fi/api/slack/events
233
385
  bot_events:
234
386
  - app_home_opened
235
387
  - app_mention
@@ -242,8 +394,8 @@ settings:
242
394
  - reaction_removed
243
395
  interactivity:
244
396
  is_enabled: true
245
- request_url: https://example.com/api/slack/interactions
246
- message_menu_options_url: https://example.com/api/slack/menu_options
397
+ request_url: https://bot.rails.fi/api/slack/interactions
398
+ message_menu_options_url: https://bot.rails.fi/api/slack/menu_options
247
399
  org_deploy_enabled: false
248
400
  socket_mode_enabled: false
249
401
  token_rotation_enabled: false
@@ -35,7 +35,7 @@ Gem::Specification.new do |gem|
35
35
  gem.add_runtime_dependency "ostruct", ">= 0.6"
36
36
 
37
37
  gem.add_development_dependency "rspec", "~> 3"
38
- gem.add_development_dependency "polyrun", ">= 2.2.0"
38
+ gem.add_development_dependency "polyrun", ">= 2.2.9"
39
39
  gem.add_development_dependency "webmock", "~> 3"
40
40
  gem.add_development_dependency "rake", "~> 13"
41
41
  gem.add_development_dependency "standard", "~> 1.52"
@@ -1,4 +1,6 @@
1
1
  require "faraday"
2
+ require "json"
3
+ require "slack_bot/response_url"
2
4
 
3
5
  module SlackBot
4
6
  class ApiResponse
@@ -16,43 +18,78 @@ module SlackBot
16
18
  end
17
19
 
18
20
  def self.rate_limit_retry_sleep_seconds(retry_after)
19
- [retry_after.to_i, RATE_LIMIT_RETRY_SLEEP_SECONDS].min
21
+ retry_after.to_i.clamp(0, RATE_LIMIT_RETRY_SLEEP_SECONDS)
20
22
  end
21
23
 
22
24
  def initialize(&block)
23
25
  @response = block.call
24
- SlackBot::DevConsole.log_output "#{self.class.name}: #{response.body}"
26
+ if response.respond_to?(:headers)
27
+ @retry_after_header = response.headers["Retry-After"]&.to_i
28
+ end
25
29
  end
26
30
 
27
31
  def ok?
28
- response.status == 200 && data["ok"]
32
+ return false unless response.status == 200
33
+
34
+ b = response.body
35
+ return true if b.is_a?(String) && b.start_with?('{"ok":true')
36
+
37
+ data["ok"]
29
38
  end
30
39
 
31
40
  def error
41
+ b = response.body
42
+ return nil if b.is_a?(String) && !b.include?('"error"')
43
+
32
44
  data["error"]
33
45
  end
34
46
 
35
47
  def rate_limited?
36
- response.status == 429 || (data["ok"] == false && data["error"] == "rate_limited")
48
+ return true if response.status == 429
49
+
50
+ b = response.body
51
+ return false if b.is_a?(String) && b.start_with?('{"ok":true')
52
+
53
+ data_rate_limited_payload
54
+ end
55
+
56
+ def data_rate_limited_payload
57
+ data["ok"] == false && data["error"] == "rate_limited"
37
58
  end
38
59
 
39
60
  def retry_after
61
+ if @retry_after_header.is_a?(Integer) && !@retry_after_header.zero?
62
+ return @retry_after_header
63
+ end
64
+
65
+ return 60 unless response.respond_to?(:headers)
66
+
40
67
  response.headers["Retry-After"]&.to_i || 60
41
68
  end
42
69
 
43
70
  def slack_error?
44
- !ok? && error.present?
71
+ return false if ok?
72
+
73
+ e = error
74
+ e.present? || response.status != 200
45
75
  end
46
76
 
47
77
  def authentication_error?
48
- slack_error? && %w[invalid_auth account_inactive].include?(error)
78
+ return false unless slack_error?
79
+
80
+ e = error
81
+ return false if e.blank?
82
+
83
+ %w[invalid_auth account_inactive].include?(e)
49
84
  end
50
85
 
51
86
  def data
52
- JSON.parse(response.body)
87
+ return @data if instance_variable_defined?(:@data)
88
+
89
+ @data = JSON.parse(response.body)
53
90
  rescue JSON::ParserError => e
54
91
  SlackBot::Logger.error("Failed to parse Slack API response: #{e.message}")
55
- {"ok" => false, "error" => "invalid_json_response"}
92
+ @data = {"ok" => false, "error" => "invalid_json_response"}
56
93
  end
57
94
  end
58
95
 
@@ -73,69 +110,85 @@ module SlackBot
73
110
  end
74
111
 
75
112
  def views_open(trigger_id:, view:)
76
- perform_request { client.post("views.open", {trigger_id: trigger_id, view: view}.to_json) }
113
+ perform_request { client.post("views.open", JSON.generate(trigger_id: trigger_id, view: view)) }
114
+ end
115
+
116
+ def views_push(trigger_id:, view:)
117
+ perform_request { client.post("views.push", JSON.generate(trigger_id: trigger_id, view: view)) }
118
+ end
119
+
120
+ def self.response_url_post(url, **message)
121
+ ResponseUrl.post(url, message)
122
+ end
123
+
124
+ def response_url_post(url, **message)
125
+ self.class.response_url_post(url, **message)
77
126
  end
78
127
 
79
- def views_update(view_id:, view:)
80
- perform_request { client.post("views.update", {view_id: view_id, view: view}.to_json) }
128
+ def views_update(view_id:, view:, hash: nil)
129
+ payload = compact_payload(view_id: view_id, view: view, hash: hash)
130
+ perform_request { client.post("views.update", JSON.generate(payload)) }
81
131
  end
82
132
 
83
133
  def chat_post_message(channel:, text:, blocks:)
84
- perform_request { client.post("chat.postMessage", {channel: channel, text: text, blocks: blocks}.to_json) }
134
+ perform_request { client.post("chat.postMessage", JSON.generate(channel: channel, text: text, blocks: blocks)) }
85
135
  end
86
136
 
87
137
  def chat_update(channel:, ts:, text:, blocks:)
88
- perform_request { client.post("chat.update", {channel: channel, ts: ts, text: text, blocks: blocks}.to_json) }
138
+ perform_request { client.post("chat.update", JSON.generate(channel: channel, ts: ts, text: text, blocks: blocks)) }
89
139
  end
90
140
 
91
141
  def chat_delete(channel:, ts:)
92
- perform_request { client.post("chat.delete", {channel: channel, ts: ts}.to_json) }
142
+ perform_request { client.post("chat.delete", JSON.generate(channel: channel, ts: ts)) }
93
143
  end
94
144
 
95
145
  def chat_unfurl(channel:, ts:, unfurls:, source: nil, unfurl_id: nil, user_auth_blocks: nil, user_auth_message: nil, user_auth_required: nil, user_auth_url: nil)
96
146
  perform_request do
97
- client.post("chat.unfurl", {
98
- channel: channel,
99
- ts: ts,
100
- unfurls: unfurls,
101
- source: source,
102
- unfurl_id: unfurl_id,
103
- user_auth_blocks: user_auth_blocks,
104
- user_auth_message: user_auth_message,
105
- user_auth_required: user_auth_required,
106
- user_auth_url: user_auth_url
107
- }.to_json)
147
+ client.post(
148
+ "chat.unfurl",
149
+ JSON.generate(
150
+ channel: channel,
151
+ ts: ts,
152
+ unfurls: unfurls,
153
+ source: source,
154
+ unfurl_id: unfurl_id,
155
+ user_auth_blocks: user_auth_blocks,
156
+ user_auth_message: user_auth_message,
157
+ user_auth_required: user_auth_required,
158
+ user_auth_url: user_auth_url
159
+ )
160
+ )
108
161
  end
109
162
  end
110
163
 
111
164
  def chat_schedule_message(channel:, text:, post_at:, blocks: nil)
112
- perform_request { client.post("chat.scheduleMessage", {channel: channel, text: text, post_at: post_at, blocks: blocks}.to_json) }
165
+ perform_request { client.post("chat.scheduleMessage", JSON.generate(channel: channel, text: text, post_at: post_at, blocks: blocks)) }
113
166
  end
114
167
 
115
168
  def scheduled_messages_list(channel: nil, cursor: nil, latest: nil, limit: nil, oldest: nil, team_id: nil)
116
169
  args = compact_payload(channel: channel, cursor: cursor, limit: limit, latest: latest, oldest: oldest, team_id: team_id)
117
- perform_request { client.post("scheduled_messages.list", args.to_json) }
170
+ perform_request { client.post("scheduled_messages.list", JSON.generate(args)) }
118
171
  end
119
172
 
120
173
  def chat_delete_scheduled_message(channel:, scheduled_message_id:)
121
- perform_request { client.post("chat.deleteScheduledMessage", {channel: channel, scheduled_message_id: scheduled_message_id}.to_json) }
174
+ perform_request { client.post("chat.deleteScheduledMessage", JSON.generate(channel: channel, scheduled_message_id: scheduled_message_id)) }
122
175
  end
123
176
 
124
177
  def chat_get_permalink(channel:, message_ts:)
125
- perform_request { client.post("chat.getPermalink", {channel: channel, message_ts: message_ts}.to_json) }
178
+ perform_request { client.post("chat.getPermalink", JSON.generate(channel: channel, message_ts: message_ts)) }
126
179
  end
127
180
 
128
181
  def users_info(user_id:)
129
- perform_request { client.post("users.info", {user: user_id}.to_json) }
182
+ perform_request { client.post("users.info", JSON.generate(user: user_id)) }
130
183
  end
131
184
 
132
185
  def views_publish(user_id:, view:)
133
- perform_request { client.post("views.publish", {user_id: user_id, view: view}.to_json) }
186
+ perform_request { client.post("views.publish", JSON.generate(user_id: user_id, view: view)) }
134
187
  end
135
188
 
136
189
  def users_list(cursor: nil, limit: 200, include_locale: nil, team_id: nil)
137
190
  args = compact_payload(cursor: cursor, limit: limit, include_locale: include_locale, team_id: team_id)
138
- perform_request { client.post("users.list", args.to_json) }
191
+ perform_request { client.post("users.list", JSON.generate(args)) }
139
192
  end
140
193
 
141
194
  def chat_post_ephemeral(channel:, user:, text:, as_user: nil, attachments: nil, blocks: nil, icon_emoji: nil, icon_url: nil, link_names: nil, parse: nil, thread_ts: nil, username: nil)
@@ -153,7 +206,7 @@ module SlackBot
153
206
  thread_ts: thread_ts,
154
207
  username: username
155
208
  )
156
- perform_request { client.post("chat.postEphemeral", args.to_json) }
209
+ perform_request { client.post("chat.postEphemeral", JSON.generate(args)) }
157
210
  end
158
211
 
159
212
  private
@@ -41,6 +41,7 @@ module SlackBot
41
41
  attr_accessor :id
42
42
  def initialize(id: nil, class_name: nil, user: nil, channel_id: nil, payload: nil, config: nil, expires_in: nil, user_scope: nil, view_id: nil)
43
43
  @id = id
44
+ @user = user
44
45
  @data = {
45
46
  class_name: class_name,
46
47
  user_id: user&.id,
@@ -56,7 +57,7 @@ module SlackBot
56
57
 
57
58
  def reload
58
59
  cached_data = read_data
59
- SlackBot::DevConsole.log_check("SlackBot::Callback#read_data: #{id} | #{cached_data}")
60
+ SlackBot::DevConsole.log_check("Read Slack callback")
60
61
  raise SlackBot::Errors::CallbackNotFound if cached_data.nil?
61
62
 
62
63
  @data = cached_data
@@ -68,7 +69,7 @@ module SlackBot
68
69
  @id = generate_id if id.blank?
69
70
  serialize_args
70
71
 
71
- SlackBot::DevConsole.log_check("SlackBot::Callback#write_data: #{id} | #{data}")
72
+ SlackBot::DevConsole.log_check("Write Slack callback")
72
73
  write_data(data)
73
74
  end
74
75
 
@@ -92,10 +93,10 @@ module SlackBot
92
93
  end
93
94
 
94
95
  def user
95
- @user ||= begin
96
- user_id = data&.dig(:user_id)
97
- config.callback_user_finder!.call(user_id) if user_id.present?
98
- end
96
+ return if user_id.blank?
97
+ return @user if @user&.id == user_id
98
+
99
+ @user = config.callback_user_finder!.call(user_id)
99
100
  end
100
101
 
101
102
  def user=(user)
@@ -199,10 +200,11 @@ module SlackBot
199
200
  config.callback_storage!.read(storage_key)
200
201
  end
201
202
 
202
- def write_data(data, expires_in: nil)
203
- expires_in ||= CALLBACK_RECORD_EXPIRES_IN
204
- config.callback_storage!.write(view_storage_key, id, expires_in: expires_in) if view_id.present?
205
- config.callback_storage!.write(storage_key, data, expires_in: expires_in)
203
+ def write_data(data)
204
+ storage = config.callback_storage!
205
+ saved = storage.write(storage_key, data, expires_in: expires_in)
206
+ storage.write(view_storage_key, id, expires_in: expires_in) if saved != false && view_id.present?
207
+ saved
206
208
  end
207
209
 
208
210
  def delete_data
@@ -56,6 +56,11 @@ module SlackBot
56
56
  @event_dispatcher_method = method_lambda
57
57
  end
58
58
 
59
+ def use(schema)
60
+ Schema::Registrar.new(self).register(schema)
61
+ end
62
+ alias_method :mount, :use
63
+
59
64
  def interaction(interaction_klass, handler_name: nil)
60
65
  handler_name ||= interaction_klass.name
61
66
  handler_class(handler_name, interaction_klass)
@@ -99,7 +104,7 @@ module SlackBot
99
104
  endpoint_config = slash_command_endpoints[url_token.to_sym]
100
105
  return if endpoint_config.blank?
101
106
 
102
- endpoint_config.find_command_config(text) || endpoint_config
107
+ endpoint_config.find_command_config(text.to_s) || endpoint_config
103
108
  end
104
109
 
105
110
  def menu_options(action_id, klass)
@@ -108,8 +113,25 @@ module SlackBot
108
113
  end
109
114
 
110
115
  def find_menu_options(action_id)
111
- @menu_options ||= {}
112
- @menu_options[action_id.to_sym]
116
+ @menu_options&.[](action_id&.to_sym)
117
+ end
118
+
119
+ alias_method :block_suggestion, :menu_options
120
+
121
+ def shortcut(callback_id, klass)
122
+ register_interaction_callback("shortcut", callback_id, klass)
123
+ end
124
+
125
+ def message_action(callback_id, klass)
126
+ register_interaction_callback("message_action", callback_id, klass)
127
+ end
128
+
129
+ def view_closed(callback_id, klass)
130
+ register_interaction_callback("view_closed", callback_id, klass)
131
+ end
132
+
133
+ def find_interaction_callback(type, callback_id)
134
+ @interaction_callbacks&.dig(type, callback_id.to_s)
113
135
  end
114
136
 
115
137
  def block_action(action_id, interaction_klass, handler_name: nil)
@@ -138,6 +160,14 @@ module SlackBot
138
160
  rescue KeyError
139
161
  raise SlackBot::Errors::HandlerClassNotFound.new(class_name, handler_classes: @handler_classes)
140
162
  end
163
+
164
+ private
165
+
166
+ def register_interaction_callback(type, callback_id, klass)
167
+ @interaction_callbacks ||= {}
168
+ (@interaction_callbacks[type] ||= {})[callback_id.to_s] = klass
169
+ interaction(klass)
170
+ end
141
171
  end
142
172
 
143
173
  class SlashCommandEndpointConfig
@@ -66,6 +66,9 @@ module SlackBot
66
66
  class UpdateModalError < SlackResponseError
67
67
  end
68
68
 
69
+ class PushModalError < SlackResponseError
70
+ end
71
+
69
72
  class PublishViewError < SlackResponseError
70
73
  end
71
74