Class: Whatsapp::MessageDispatcher Private
- Inherits:
-
Object
- Object
- Whatsapp::MessageDispatcher
- Defined in:
- lib/whatsapp/message_dispatcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Dispatches incoming messages to the configured MessageHandler.
Resolves the handler from Configuration#message_handler (Class or String), instantiates it, and calls +#call+ with the message and session name. Errors are caught and logged, never propagated.
Instance Method Summary collapse
-
#dispatch(message) ⇒ void
private
Dispatch a message to the configured handler.
-
#initialize(session_name) ⇒ MessageDispatcher
constructor
private
A new instance of MessageDispatcher.
Constructor Details
#initialize(session_name) ⇒ MessageDispatcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MessageDispatcher.
11 12 13 |
# File 'lib/whatsapp/message_dispatcher.rb', line 11 def initialize(session_name) @session_name = session_name end |
Instance Method Details
#dispatch(message) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Dispatch a message to the configured handler.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/whatsapp/message_dispatcher.rb', line 19 def dispatch() handler = resolve_handler return unless handler handler.new.call(, session: @session_name) rescue => e Whatsapp.logger.error "MessageHandler error", handler: handler&.name || handler.to_s, session: @session_name, error: e. end |