[verified] Restore Chatwoot Hub compatibility APIs
This commit is contained in:
@@ -5,6 +5,10 @@ class ChatwootHub
|
||||
DEFAULT_BASE_URL
|
||||
end
|
||||
|
||||
def self.push_notification_url
|
||||
"#{base_url}/send_push"
|
||||
end
|
||||
|
||||
def self.billing_base_url
|
||||
"#{base_url}/billing"
|
||||
end
|
||||
@@ -38,6 +42,29 @@ class ChatwootHub
|
||||
support_identifier_hash: InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_IDENTIFIER_HASH')&.value
|
||||
}
|
||||
end
|
||||
|
||||
def self.instance_config
|
||||
{
|
||||
installation_identifier: installation_identifier,
|
||||
installation_version: Chatwoot.config[:version],
|
||||
installation_host: URI.parse(ENV.fetch('FRONTEND_URL', '')).host,
|
||||
installation_env: ENV.fetch('INSTALLATION_ENV', ''),
|
||||
edition: ENV.fetch('CW_EDITION', '')
|
||||
}
|
||||
end
|
||||
|
||||
def self.send_push(fcm_options)
|
||||
send_push_with_response(fcm_options)
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||
Rails.logger.error "Exception: #{e.message}"
|
||||
rescue StandardError => e
|
||||
ChatwootExceptionTracker.new(e).capture_exception
|
||||
end
|
||||
|
||||
def self.send_push_with_response(fcm_options)
|
||||
info = { fcm_options: fcm_options }
|
||||
RestClient.post(push_notification_url, info.merge(instance_config).to_json, { content_type: :json, accept: :json })
|
||||
end
|
||||
end
|
||||
|
||||
ChatwootHub.singleton_class.prepend_mod_with('ChatwootHub')
|
||||
|
||||
@@ -7,6 +7,11 @@ describe ChatwootHub do
|
||||
expect(described_class).not_to respond_to(:emit_event)
|
||||
end
|
||||
|
||||
it 'retains push and instance compatibility APIs for the push-relay task' do
|
||||
expect(described_class).to respond_to(:push_notification_url, :send_push, :send_push_with_response, :instance_config)
|
||||
expect(described_class.push_notification_url).to eq('https://hub.2.chatwoot.com/send_push')
|
||||
end
|
||||
|
||||
describe '.base_url' do
|
||||
it 'uses the static hub url' do
|
||||
expect(described_class::DEFAULT_BASE_URL).to eq('https://hub.2.chatwoot.com')
|
||||
|
||||
Reference in New Issue
Block a user