Class: WhatsAppNotifier::Providers::WebAutomation
- Defined in:
- lib/whatsapp_notifier/providers/web_automation.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #connection_status(metadata: {}) ⇒ Object
- #deliver(payload) ⇒ Object
-
#initialize(configuration:) ⇒ WebAutomation
constructor
A new instance of WebAutomation.
- #scan_qr(metadata: {}) ⇒ Object
Constructor Details
#initialize(configuration:) ⇒ WebAutomation
Returns a new instance of WebAutomation.
4 5 6 7 |
# File 'lib/whatsapp_notifier/providers/web_automation.rb', line 4 def initialize(configuration:) super @store = Session::Store.new(path: configuration.web_session_path) end |
Instance Method Details
#connection_status(metadata: {}) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/whatsapp_notifier/providers/web_automation.rb', line 42 def connection_status(metadata: {}) raise ConfigurationError, "web automation provider is disabled" unless configuration.web_automation_enabled adapter = configuration.web_adapter raise ConfigurationError, "web_adapter must be configured for web_automation provider" unless adapter.respond_to?(:connection_status) adapter.connection_status(metadata: ) end |
#deliver(payload) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/whatsapp_notifier/providers/web_automation.rb', line 9 def deliver(payload) raise ConfigurationError, "web automation provider is disabled" unless configuration.web_automation_enabled adapter = configuration.web_adapter raise ConfigurationError, "web_adapter must be configured for web_automation provider" unless adapter.respond_to?(:send_message) warn_risk_once session = session_for(payload.fetch(:metadata, {})) response = adapter.(payload: payload, session: session) persist_session(response.fetch(:session, {}), payload.fetch(:metadata, {})) Result.new( success: response.fetch(:success), provider: :web_automation, message_id: response[:message_id], error_code: response[:error_code], error_message: response[:error_message], wait_seconds: response[:wait_seconds], metadata: response.fetch(:metadata, {}) ) rescue StandardError => e Result.new(success: false, provider: :web_automation, error_code: :delivery_exception, error_message: e.) end |
#scan_qr(metadata: {}) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/whatsapp_notifier/providers/web_automation.rb', line 33 def scan_qr(metadata: {}) raise ConfigurationError, "web automation provider is disabled" unless configuration.web_automation_enabled adapter = configuration.web_adapter raise ConfigurationError, "web_adapter must be configured for web_automation provider" unless adapter.respond_to?(:fetch_qr_code) Session::QrService.new(store: @store, adapter: adapter).qr_code(metadata: ) end |