feat: Use relay server for self-hosted mobile push notifications (#2757)

This commit is contained in:
Pranav Raj S
2021-08-17 01:44:16 +05:30
committed by GitHub
parent 319412f6dc
commit ed317c5bb3
4 changed files with 33 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ class ChatwootHub
BASE_URL = ENV['CHATWOOT_HUB_URL'] || 'https://hub.2.chatwoot.com'
PING_URL = "#{BASE_URL}/ping".freeze
REGISTRATION_URL = "#{BASE_URL}/instances".freeze
PUSH_NOTIFICATION_URL = "#{BASE_URL}/send_push".freeze
EVENTS_URL = "#{BASE_URL}/events".freeze
def self.installation_identifier
@@ -51,7 +52,16 @@ class ChatwootHub
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
Rails.logger.info "Exception: #{e.message}"
rescue StandardError => e
Raven.capture_exception(e)
Sentry.capture_exception(e)
end
def self.send_browser_push(fcm_token_list, fcm_options)
info = { fcm_token_list: fcm_token_list, fcm_options: fcm_options }
RestClient.post(PUSH_NOTIFICATION_URL, info.merge(instance_config).to_json, { content_type: :json, accept: :json })
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
Rails.logger.info "Exception: #{e.message}"
rescue StandardError => e
Sentry.capture_exception(e)
end
def self.emit_event(event_name, event_data)