chore: code cleanup
This commit is contained in:
@@ -40,7 +40,7 @@ class SuperAdmin::AppConfigsController < SuperAdmin::ApplicationController
|
||||
when 'email'
|
||||
['MAILER_INBOUND_EMAIL_DOMAIN']
|
||||
else
|
||||
%w[ENABLE_ACCOUNT_SIGNUP]
|
||||
%w[ENABLE_ACCOUNT_SIGNUP FIREBASE_PROJECT_ID FIREBASE_CREDENTIALS]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
class FCMService
|
||||
SCOPES = ['https://www.googleapis.com/auth/firebase.messaging'].freeze
|
||||
|
||||
def initialize(credentials_path, project_id)
|
||||
@credentials_path = credentials_path
|
||||
def initialize(project_id)
|
||||
@project_id = project_id
|
||||
@token_info = nil
|
||||
end
|
||||
|
||||
def fcm_client
|
||||
FCM.new(current_token, @credentials_path, @project_id)
|
||||
FCM.new(current_token, credentials_json, @project_id)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -24,7 +23,7 @@ class FCMService
|
||||
|
||||
def generate_token
|
||||
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
|
||||
json_key_io: File.open(@credentials_path),
|
||||
json_key_io: StringIO.new(GlobalConfigService.load('FIREBASE_CREDENTIALS', nil)),
|
||||
scope: SCOPES
|
||||
)
|
||||
token = authorizer.fetch_access_token!
|
||||
|
||||
@@ -71,11 +71,12 @@ class Notification::PushNotificationService
|
||||
end
|
||||
|
||||
def send_fcm_push(subscription)
|
||||
return unless ENV['GOOGLE_APPLICATION_CREDENTIALS'] && ENV['FIREBASE_PROJECT_ID']
|
||||
return unless ENV['FIREBASE_PROJECT_ID']
|
||||
return unless subscription.fcm?
|
||||
|
||||
fcm_service = FCMService.new(ENV.fetch('GOOGLE_APPLICATION_CREDENTIALS', nil),
|
||||
ENV.fetch('FIREBASE_PROJECT_ID', nil))
|
||||
fcm_service = FCMService.new(
|
||||
ENV.fetch('FIREBASE_PROJECT_ID', nil)
|
||||
)
|
||||
fcm = fcm_service.fcm_client
|
||||
message = {
|
||||
'token': subscription.subscription_attributes['push_token'],
|
||||
|
||||
@@ -204,3 +204,16 @@
|
||||
locked: false
|
||||
description: 'Disable rendering profile update page for users'
|
||||
## ------ End of Configs added for enterprise clients ------ ##
|
||||
|
||||
## ------ Configs added for FCM v1 notifications ------ ##
|
||||
- name: FIREBASE_PROJECT_ID
|
||||
display_title: 'Firebase Project ID'
|
||||
value:
|
||||
locked: false
|
||||
description: 'Firebase project ID'
|
||||
- name: FIREBASE_CREDENTIALS
|
||||
display_title: 'Firebase Credentials'
|
||||
value:
|
||||
locked: false
|
||||
description: 'Contents on your firebase credentials json file'
|
||||
## ------ End of Configs added for FCM v1 notifications ------ ##
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
class ChatwootHub
|
||||
BASE_URL = ENV.fetch('CHATWOOT_HUB_URL', 'https://hub.2.chatwoot.com')
|
||||
BASE_URL = ENV.fetch('CHATWOOT_HUB_URL', 'http://localhost:3001')
|
||||
PING_URL = "#{BASE_URL}/ping".freeze
|
||||
REGISTRATION_URL = "#{BASE_URL}/instances".freeze
|
||||
PUSH_NOTIFICATION_URL = "#{BASE_URL}/send_push".freeze
|
||||
|
||||
Reference in New Issue
Block a user