diff --git a/app/controllers/super_admin/app_configs_controller.rb b/app/controllers/super_admin/app_configs_controller.rb index 9d9494fc4..b8f3bd9a9 100644 --- a/app/controllers/super_admin/app_configs_controller.rb +++ b/app/controllers/super_admin/app_configs_controller.rb @@ -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 diff --git a/app/services/notification/fcm_service.rb b/app/services/notification/fcm_service.rb index 3074e6e69..004654988 100644 --- a/app/services/notification/fcm_service.rb +++ b/app/services/notification/fcm_service.rb @@ -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! diff --git a/app/services/notification/push_notification_service.rb b/app/services/notification/push_notification_service.rb index 339a3e28e..6990d2559 100644 --- a/app/services/notification/push_notification_service.rb +++ b/app/services/notification/push_notification_service.rb @@ -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'], diff --git a/config/installation_config.yml b/config/installation_config.yml index 419a63352..5784c3b6e 100644 --- a/config/installation_config.yml +++ b/config/installation_config.yml @@ -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 ------ ## diff --git a/lib/chatwoot_hub.rb b/lib/chatwoot_hub.rb index 6d28b10fa..3606ee3cd 100644 --- a/lib/chatwoot_hub.rb +++ b/lib/chatwoot_hub.rb @@ -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