Class: BoltRb::Handlers::ViewSubmissionHandler
- Defined in:
- lib/bolt_rb/handlers/view_submission_handler.rb
Overview
Handler for Slack view submissions (modal form submissions)
This handler provides the view DSL for matching view_submission payloads.
View submissions are triggered when users click the submit button on modals
opened via views.open or views.push.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.matches?(payload) ⇒ Boolean
Determines if this handler matches the given payload.
-
.view(callback_id) ⇒ void
Configures which callback_id this handler responds to.
Instance Method Summary collapse
-
#callback_id ⇒ String?
Returns the callback_id from the view.
-
#private_metadata ⇒ String?
Returns the private_metadata from the view.
-
#response_urls ⇒ Array<Hash>
Returns the response URLs for block-based responses.
-
#user_id ⇒ String?
Returns the user ID from the payload.
-
#values ⇒ Hash
Returns the state values from the submitted form.
-
#view ⇒ Hash?
Returns the view object from the payload.
-
#view_hash ⇒ String?
Returns the hash value of the submitted view.
Methods inherited from Base
#ack, #call, #channel, #client, #handle, inherited, #initialize, middleware_stack, #payload, #respond, #say, use, #user
Constructor Details
This class inherits a constructor from BoltRb::Handlers::Base
Class Method Details
.matches?(payload) ⇒ Boolean
Determines if this handler matches the given payload
Checks if the payload is a view_submission type and if the callback_id matches the configured pattern.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bolt_rb/handlers/view_submission_handler.rb', line 72 def matches?(payload) return false unless matcher_config return false unless payload['type'] == 'view_submission' view_callback_id = payload.dig('view', 'callback_id') return false unless view_callback_id if matcher_config[:callback_id].is_a?(Regexp) matcher_config[:callback_id].match?(view_callback_id) else view_callback_id == matcher_config[:callback_id] end end |
.view(callback_id) ⇒ void
This method returns an undefined value.
Configures which callback_id this handler responds to
58 59 60 61 62 63 |
# File 'lib/bolt_rb/handlers/view_submission_handler.rb', line 58 def view(callback_id) @matcher_config = { type: :view_submission, callback_id: callback_id } end |
Instance Method Details
#callback_id ⇒ String?
Returns the callback_id from the view
97 98 99 |
# File 'lib/bolt_rb/handlers/view_submission_handler.rb', line 97 def callback_id view&.dig('callback_id') end |
#private_metadata ⇒ String?
Returns the private_metadata from the view
Private metadata is a string field you can use to pass data between the view open and submission events. Often used to store IDs.
107 108 109 |
# File 'lib/bolt_rb/handlers/view_submission_handler.rb', line 107 def view&.dig('private_metadata') end |
#response_urls ⇒ Array<Hash>
Returns the response URLs for block-based responses
Only present if the modal was opened from a message interaction.
142 143 144 |
# File 'lib/bolt_rb/handlers/view_submission_handler.rb', line 142 def response_urls payload['response_urls'] || [] end |
#user_id ⇒ String?
Returns the user ID from the payload
133 134 135 |
# File 'lib/bolt_rb/handlers/view_submission_handler.rb', line 133 def user_id payload.dig('user', 'id') end |
#values ⇒ Hash
Returns the state values from the submitted form
The values hash is keyed by block_id, then action_id, then contains the input value (format depends on input type).
126 127 128 |
# File 'lib/bolt_rb/handlers/view_submission_handler.rb', line 126 def values view&.dig('state', 'values') || {} end |
#view ⇒ Hash?
Returns the view object from the payload
90 91 92 |
# File 'lib/bolt_rb/handlers/view_submission_handler.rb', line 90 def view payload['view'] end |
#view_hash ⇒ String?
Returns the hash value of the submitted view
Used for optimistic locking when updating views.
151 152 153 |
# File 'lib/bolt_rb/handlers/view_submission_handler.rb', line 151 def view_hash view&.dig('hash') end |