require 'uri' class ChatwootHub def self.installation_identifier identifier = InstallationConfig.find_by(name: 'INSTALLATION_IDENTIFIER')&.value identifier ||= InstallationConfig.create!(name: 'INSTALLATION_IDENTIFIER', value: SecureRandom.uuid).value identifier end def self.pricing_plan return 'community' unless ChatwootApp.enterprise? InstallationConfig.find_by(name: 'INSTALLATION_PRICING_PLAN')&.value || 'community' end def self.pricing_plan_quantity return 0 unless ChatwootApp.enterprise? InstallationConfig.find_by(name: 'INSTALLATION_PRICING_PLAN_QUANTITY')&.value || 0 end def self.billing_url configured_url = ENV['CHATWOOT_BILLING_URL'].to_s return if configured_url.empty? uri = URI.parse(configured_url) return unless uri.scheme == 'https' && uri.host.present? && uri.user.nil? && uri.password.nil? configured_url rescue URI::InvalidURIError nil end def self.support_config { support_website_token: InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_WEBSITE_TOKEN')&.value, support_script_url: InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_SCRIPT_URL')&.value, support_identifier_hash: InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_IDENTIFIER_HASH')&.value } end end ChatwootHub.singleton_class.prepend_mod_with('ChatwootHub')