diff --git a/.env.example b/.env.example index 443baeb57..cd20ca72a 100644 --- a/.env.example +++ b/.env.example @@ -258,9 +258,6 @@ AZURE_APP_SECRET= # contact_inboxes with no conversation older than 90 days will be removed # REMOVE_STALE_CONTACT_INBOX_JOB_STATUS=false -# NOTE: Useful when running inside docker-compose network to link to external domain -FRONTEND_URL_EXTERNAL= - # Baileys API Whatsapp provider BAILEYS_PROVIDER_DEFAULT_CLIENT_NAME=Chatwoot BAILEYS_PROVIDER_DEFAULT_URL=http://localhost:3025 diff --git a/app/helpers/frontend_urls_helper.rb b/app/helpers/frontend_urls_helper.rb index 67b117f06..967483c7b 100644 --- a/app/helpers/frontend_urls_helper.rb +++ b/app/helpers/frontend_urls_helper.rb @@ -1,7 +1,7 @@ module FrontendUrlsHelper def frontend_url(path, **query_params) url_params = query_params.blank? ? '' : "?#{query_params.to_query}" - host = ENV.fetch('FRONTEND_URL_EXTERNAL', root_url) + host = ENV.fetch('FRONTEND_URL', root_url) host = "#{host}/" unless host.end_with?('/') "#{host}app/#{path}#{url_params}" end diff --git a/app/models/channel/whatsapp.rb b/app/models/channel/whatsapp.rb index 849ed1ca8..41d1a5960 100644 --- a/app/models/channel/whatsapp.rb +++ b/app/models/channel/whatsapp.rb @@ -54,6 +54,10 @@ class Channel::Whatsapp < ApplicationRecord end end + def use_internal_host? + provider == 'baileys' && ENV.fetch('BAILEYS_PROVIDER_USE_INTERNAL_HOST_URL', false) + end + def mark_message_templates_updated # rubocop:disable Rails/SkipsModelValidations update_column(:message_templates_last_updated, Time.zone.now) diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 20c8dc610..8c4236b2d 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -159,15 +159,17 @@ class Inbox < ApplicationRecord end def callback_webhook_url + host = ENV.fetch('FRONTEND_URL', nil) case channel_type when 'Channel::TwilioSms' - "#{ENV.fetch('FRONTEND_URL', nil)}/twilio/callback" + "#{host}/twilio/callback" when 'Channel::Sms' - "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/sms/#{channel.phone_number.delete_prefix('+')}" + "#{host}/webhooks/sms/#{channel.phone_number.delete_prefix('+')}" when 'Channel::Line' - "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/line/#{channel.line_channel_id}" + "#{host}/webhooks/line/#{channel.line_channel_id}" when 'Channel::Whatsapp' - "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/whatsapp/#{channel.phone_number}" + host = ENV.fetch('INTERNAL_HOST_URL', nil) if channel.use_internal_host? + "#{host}/webhooks/whatsapp/#{channel.phone_number}" end end diff --git a/config/environments/development.rb b/config/environments/development.rb index 7a41f426a..557000065 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -34,8 +34,7 @@ Rails.application.configure do config.active_job.queue_adapter = :sidekiq - host = ENV['FRONTEND_URL_EXTERNAL'].presence || ENV['FRONTEND_URL'] - Rails.application.routes.default_url_options = { host: host } + Rails.application.routes.default_url_options = { host: ENV['FRONTEND_URL'] } # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/production.rb b/config/environments/production.rb index 303a42fa3..a9504fc5c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -102,6 +102,5 @@ Rails.application.configure do # :sendgrid for Sendgrid config.action_mailbox.ingress = ENV.fetch('RAILS_INBOUND_EMAIL_SERVICE', 'relay').to_sym - host = ENV['FRONTEND_URL_EXTERNAL'].presence || ENV['FRONTEND_URL'] - Rails.application.routes.default_url_options = { host: host } + Rails.application.routes.default_url_options = { host: ENV['FRONTEND_URL'] } end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index df7fcea00..ed7cc0e84 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -50,8 +50,7 @@ Rails.application.configure do # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "chatwoot_#{Rails.env}" - host = ENV['FRONTEND_URL_EXTERNAL'].presence || ENV['FRONTEND_URL'] - Rails.application.routes.default_url_options = { host: host } + Rails.application.routes.default_url_options = { host: ENV['FRONTEND_URL'] } # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). diff --git a/spec/helpers/frontend_urls_helper_spec.rb b/spec/helpers/frontend_urls_helper_spec.rb index beefd23e6..c522d0ee9 100644 --- a/spec/helpers/frontend_urls_helper_spec.rb +++ b/spec/helpers/frontend_urls_helper_spec.rb @@ -13,13 +13,5 @@ describe FrontendUrlsHelper do expect(helper.frontend_url('dashboard', p1: 'p1', p2: 'p2')).to eq 'http://test.host/app/dashboard?p1=p1&p2=p2' end end - - context 'with set FRONTEND_URL_EXTERNAL' do - it 'creates path correctly' do - with_modified_env 'FRONTEND_URL_EXTERNAL' => 'http://external.url/' do - expect(helper.frontend_url('dashboard')).to eq 'http://external.url/app/dashboard' - end - end - end end end