Class: BoltRb::Handlers::ViewClosedHandler
- Defined in:
- lib/bolt_rb/handlers/view_closed_handler.rb
Overview
Handler for Slack view closed events (modal cancellation/dismissal)
This handler provides the view_closed DSL for matching view_closed payloads.
View closed events are triggered when users close a modal by clicking the X
button or Cancel, but only when the modal was opened with notify_on_close: true.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.matches?(payload) ⇒ Boolean
Determines if this handler matches the given payload.
-
.view_closed(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.
-
#is_cleared? ⇒ Boolean
Returns whether the view was cleared programmatically.
-
#private_metadata ⇒ String?
Returns the private_metadata from the view.
-
#user_id ⇒ String?
Returns the user ID from the payload.
-
#view ⇒ Hash?
Returns the view object from the payload.
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_closed type and if the callback_id matches the configured pattern.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bolt_rb/handlers/view_closed_handler.rb', line 68 def matches?(payload) return false unless matcher_config return false unless payload['type'] == 'view_closed' 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_closed(callback_id) ⇒ void
This method returns an undefined value.
Configures which callback_id this handler responds to
54 55 56 57 58 59 |
# File 'lib/bolt_rb/handlers/view_closed_handler.rb', line 54 def view_closed(callback_id) @matcher_config = { type: :view_closed, callback_id: callback_id } end |
Instance Method Details
#callback_id ⇒ String?
Returns the callback_id from the view
93 94 95 |
# File 'lib/bolt_rb/handlers/view_closed_handler.rb', line 93 def callback_id view&.dig('callback_id') end |
#is_cleared? ⇒ Boolean
Returns whether the view was cleared programmatically
This is true when the view was dismissed via views.update with a clear_on_close response, rather than the user clicking X or Cancel.
113 114 115 |
# File 'lib/bolt_rb/handlers/view_closed_handler.rb', line 113 def is_cleared? payload['is_cleared'] == true 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 close events. Often used to store IDs for cleanup.
103 104 105 |
# File 'lib/bolt_rb/handlers/view_closed_handler.rb', line 103 def view&.dig('private_metadata') end |
#user_id ⇒ String?
Returns the user ID from the payload
120 121 122 |
# File 'lib/bolt_rb/handlers/view_closed_handler.rb', line 120 def user_id payload.dig('user', 'id') end |
#view ⇒ Hash?
Returns the view object from the payload
86 87 88 |
# File 'lib/bolt_rb/handlers/view_closed_handler.rb', line 86 def view payload['view'] end |