grape-slack-bot 2.1.3 → 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: c3e52396043a337cfa348d788ca11ea7d6b76c8486d080a2a0d43c69cf73ad4e
4
- data.tar.gz: a20fd5e43a9695978b06250cd66a9c13bc2732b9246c9a1a8685e1986b9302f1
3
+ metadata.gz: e439c9df6bc7266e9b6bc96044291cd195ca2bc803ceec0ccd908ba1f694349a
4
+ data.tar.gz: bd637145592b5e66e26d4d23711baf7e5c2b4f6eb2d5531003bd0a09253184e0
5
5
  SHA512:
6
- metadata.gz: 4a25326a96fafe69c94ff3a2490bc9b674e5f8ee40e3c7dc481a5fef4f7ccb3a19cbc1fe471f6fb155b605e4c544c68785bf817a1a4f1a8686351e672201cd59
7
- data.tar.gz: bb3fd2179189e08f5795a4a6cccbbb82f96d4157e455fbd0f28b955a7ca5ae7112b9da548326d1523aacfd2fb5640972aecaa05677ce9ff2b7bad760106f3822
6
+ metadata.gz: 89d89feb6e813740c0ad667ce118089dbe147971b683acc256f587ebcd1a6d3bbf67810bfda92226652597d8c284abc9c80eb809e24d27b9acd11fc1beb63bab
7
+ data.tar.gz: e3595568199fa5ed01280157b20f2418a5ec35c13d1e1483d872d9120e34ddd52e26c87de7fdb463ac1a31392d406584834f11bc59293e92946bbfcf58620586
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
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
+
3
12
  ## 2.1.3 (2026-11-07)
4
13
 
5
14
  - Memoize parsed JSON in `SlackBot::ApiResponse#data` so repeated reads do not re-parse the response body
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
@@ -1,5 +1,6 @@
1
1
  require "faraday"
2
2
  require "json"
3
+ require "slack_bot/response_url"
3
4
 
4
5
  module SlackBot
5
6
  class ApiResponse
@@ -112,8 +113,21 @@ module SlackBot
112
113
  perform_request { client.post("views.open", JSON.generate(trigger_id: trigger_id, view: view)) }
113
114
  end
114
115
 
115
- def views_update(view_id:, view:)
116
- perform_request { client.post("views.update", JSON.generate(view_id: view_id, view: view)) }
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)
126
+ end
127
+
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)) }
117
131
  end
118
132
 
119
133
  def chat_post_message(channel:, text:, blocks:)
@@ -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
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support"
2
4
  require "active_support/core_ext/object"
3
5
  require "active_support/security_utils"
@@ -14,6 +16,9 @@ module SlackBot
14
16
  TIMESTAMP_TOLERANCE_SECONDS = 300
15
17
  # Minimum length for Slack signing secret (Slack's requirement)
16
18
  MIN_SIGNING_SECRET_LENGTH = 32
19
+ PAYLOAD_OBJECTS = %w[team user view].freeze
20
+ ROUTE_IDENTIFIERS = %w[callback_id action_id].freeze
21
+ NEW_INTERACTION_TYPES = %w[shortcut message_actions message_action view_closed].freeze
17
22
 
18
23
  def fetch_team_id
19
24
  params.dig("team_id") || params.dig("team", "id")
@@ -23,6 +28,10 @@ module SlackBot
23
28
  params.dig("user_id") || params.dig("user", "id") || params.dig("event", "user")
24
29
  end
25
30
 
31
+ def current_user
32
+ resolve_user_session(fetch_team_id, fetch_user_id)&.user
33
+ end
34
+
26
35
  def verify_slack_signature!
27
36
  remove_instance_variable(:@request_body_content) if instance_variable_defined?(:@request_body_content)
28
37
 
@@ -74,7 +83,7 @@ module SlackBot
74
83
  end
75
84
 
76
85
  def url_verification(params)
77
- SlackBot::DevConsole.log_input "SlackApi::Events#url_verification: #{params.inspect}"
86
+ SlackBot::DevConsole.log_input "Slack URL verification"
78
87
  {challenge: params[:challenge]}
79
88
  end
80
89
 
@@ -127,13 +136,62 @@ module SlackBot
127
136
  end
128
137
 
129
138
  def parse_interaction_payload!(raw_payload)
130
- JSON.parse(raw_payload)
131
- rescue JSON::ParserError => e
132
- raise SlackBot::Errors::InvalidPayloadError.new("Invalid JSON payload: #{e.message}")
139
+ payload = JSON.parse(raw_payload) if raw_payload.is_a?(String)
140
+ raise SlackBot::Errors::InvalidPayloadError.new("Invalid JSON payload: expected an object") unless payload.is_a?(Hash)
141
+
142
+ validate_interaction_shape!(payload)
143
+ payload
144
+ rescue JSON::ParserError
145
+ raise SlackBot::Errors::InvalidPayloadError.new("Invalid JSON payload"), cause: nil
146
+ end
147
+
148
+ def validate_interaction_shape!(payload)
149
+ return if PAYLOAD_OBJECTS.all? { |field| payload[field].nil? || payload[field].is_a?(Hash) } &&
150
+ ROUTE_IDENTIFIERS.all? { |field| payload[field].nil? || payload[field].is_a?(String) } &&
151
+ valid_action_list?(payload["actions"])
152
+
153
+ raise SlackBot::Errors::InvalidPayloadError.new("Invalid Slack payload fields")
133
154
  end
134
155
 
135
- def resolve_action_user(payload)
136
- resolve_user_session(payload.dig("user", "team_id"), payload.dig("user", "id"))
156
+ def valid_action_list?(actions)
157
+ actions.nil? || (actions.is_a?(Array) && actions.all? do |action|
158
+ action.is_a?(Hash) && (action["action_id"].nil? || action["action_id"].is_a?(String))
159
+ end)
160
+ end
161
+
162
+ def authorize_interaction_team!(payload)
163
+ team_id = interaction_team_id(payload)
164
+ raise SlackBot::Errors::TeamAuthenticationError.new("Team is not authorized") if team_id.blank?
165
+
166
+ verify_slack_team!(team_id)
167
+ team_id
168
+ end
169
+
170
+ def resolve_action_user(payload, team_id)
171
+ resolve_user_session(team_id, payload.dig("user", "id"))
172
+ end
173
+
174
+ def load_menu_options(options_params, user)
175
+ klass = slack_bot_config.find_menu_options(options_params[:action_id])
176
+ raise SlackBot::Errors::MenuOptionsNotImplemented.new if klass.blank?
177
+
178
+ klass.new(current_user: user, params: options_params, config: slack_bot_config).call
179
+ end
180
+
181
+ def empty_slack_ack!
182
+ api_format :txt
183
+ blank_slack_response!
184
+ end
185
+
186
+ def invoke_slack_handler(handler)
187
+ result = handler.call
188
+ if handler.is_a?(Schema::Responses)
189
+ return empty_slack_ack! if result.blank?
190
+
191
+ status 200
192
+ end
193
+
194
+ result
137
195
  end
138
196
 
139
197
  def blank_slack_response!
@@ -174,15 +232,15 @@ module SlackBot
174
232
  command_klass = command_config&.command_klass
175
233
  raise SlackBot::Errors::SlashCommandNotImplemented.new if command_klass.blank?
176
234
 
177
- args = params[:text].gsub(/^#{command_config.full_token}\s?/, "")
178
- SlackBot::DevConsole.log_input "SlackApi::SlashCommands#post: #{command_config.url_token} | #{command_config.full_token} | #{args}"
235
+ args = params[:text].to_s.sub(/\A#{Regexp.escape(command_config.full_token)}\s?/, "")
236
+ SlackBot::DevConsole.log_input "Slack slash command"
179
237
 
180
238
  action = command_klass.new(current_user: current_user, params: params, args: args, config: slack_bot_config)
181
239
  verify_slack_team! if action.only_slack_team?
182
240
  verify_direct_message_channel! if action.only_direct_message?
183
241
  verify_current_user! if action.only_user?
184
242
 
185
- result = action.call
243
+ result = invoke_slack_handler(action)
186
244
  return blank_slack_response! unless result
187
245
 
188
246
  result
@@ -193,12 +251,13 @@ module SlackBot
193
251
  def self.add_interactions_resource!(base)
194
252
  base.resource :interactions do
195
253
  post do
196
- payload = parse_interaction_payload!(params[:payload])
197
- verify_slack_team!(interaction_team_id(payload))
198
- action_user = resolve_action_user(payload)&.user
254
+ payload = parse_interaction_payload!(request.POST["payload"])
255
+ team_id = authorize_interaction_team!(payload)
256
+ action_user = resolve_action_user(payload, team_id)&.user
199
257
 
200
258
  result = route_interaction(payload: payload, user: action_user, params: params)
201
259
 
260
+ status 200 if GrapeHelpers::NEW_INTERACTION_TYPES.include?(payload["type"])
202
261
  return blank_slack_response! if result.blank? || result == false
203
262
 
204
263
  result
@@ -230,17 +289,24 @@ module SlackBot
230
289
  def self.add_menu_options_resource!(base)
231
290
  base.resource :menu_options do
232
291
  get do
233
- SlackBot::DevConsole.log_input "SlackApi::MenuOptions#get: #{params.inspect}"
292
+ SlackBot::DevConsole.log_input "Slack menu options"
234
293
 
235
294
  verify_slack_team!
236
- menu_options_klass = slack_bot_config.find_menu_options(params[:action_id])
237
- raise SlackBot::Errors::MenuOptionsNotImplemented.new if menu_options_klass.blank?
238
-
239
- menu_options = menu_options_klass.new(current_user: current_user, params: params, config: slack_bot_config).call
295
+ menu_options = load_menu_options(params, current_user)
240
296
  return blank_slack_response! if menu_options.blank?
241
297
 
242
298
  menu_options
243
299
  end
300
+
301
+ post do
302
+ payload = parse_interaction_payload!(request.POST["payload"])
303
+ team_id = authorize_interaction_team!(payload)
304
+ raise SlackBot::Errors::UnknownActionTypeError.new(payload["type"]) unless payload["type"] == "block_suggestion"
305
+
306
+ user = resolve_action_user(payload, team_id)&.user
307
+ status 200
308
+ load_menu_options(payload.with_indifferent_access, user).presence || {options: []}
309
+ end
244
310
  end
245
311
  end
246
312
  end
@@ -8,7 +8,7 @@ module SlackBot
8
8
  return false if event.blank?
9
9
  return false if bot_message_event?(event)
10
10
 
11
- SlackBot::DevConsole.log_input "SlackApi::Events#events_callback: #{params.inspect}"
11
+ SlackBot::DevConsole.log_input "Slack event callback"
12
12
  handler = event_handler_for(params)
13
13
  return false if handler.blank?
14
14
 
@@ -40,14 +40,19 @@ module SlackBot
40
40
 
41
41
  def event_handler_for(params)
42
42
  event_type = params[:event][:type] || params[:event]["type"]
43
- slack_bot_config.find_event_handler(event_type.to_sym)
43
+ slack_bot_config.find_event_handler(event_type) if event_type.is_a?(String) || event_type.is_a?(Symbol)
44
44
  end
45
45
 
46
46
  def run_event_handler(handler, params)
47
47
  current_user = resolve_event_user(params)
48
- return dispatch_event(handler: handler, params: params, current_user: current_user) if slack_bot_config.event_dispatcher_method
49
-
50
- handler.new(params: params, current_user: current_user).call
48
+ if slack_bot_config.event_dispatcher_method
49
+ result = dispatch_event(handler: handler, params: params, current_user: current_user)
50
+ return (handler <= Schema::Event) ? empty_slack_ack! : result
51
+ end
52
+
53
+ arguments = {params: params, current_user: current_user}
54
+ arguments[:config] = slack_bot_config if handler <= Schema::Event
55
+ invoke_slack_handler(handler.new(**arguments))
51
56
  end
52
57
  end
53
58
  end