diff --git a/Gemfile b/Gemfile index 53ba9f783..269614d8b 100644 --- a/Gemfile +++ b/Gemfile @@ -121,6 +121,8 @@ gem 'sentry-sidekiq', '>= 5.19.0', require: false gem 'sidekiq', '>= 7.3.1' # We want cron jobs gem 'sidekiq-cron', '>= 1.12.0' +# for sidekiq healthcheck +gem 'sidekiq_alive' ##-- Push notification service --## gem 'fcm' diff --git a/Gemfile.lock b/Gemfile.lock index d55cfa0a9..405300a7c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -359,6 +359,7 @@ GEM grpc (1.72.0-x86_64-linux) google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) + gserver (0.0.1) haikunator (1.1.1) hairtrigger (1.0.0) activerecord (>= 6.0, < 8) @@ -477,7 +478,7 @@ GEM mime-types-data (3.2023.0218.1) mini_magick (4.12.0) mini_mime (1.1.5) - mini_portile2 (2.8.8) + mini_portile2 (2.8.9) minitest (5.25.5) mock_redis (0.36.0) ruby2_keywords @@ -508,14 +509,14 @@ GEM newrelic_rpm (9.6.0) base64 nio4r (2.7.3) - nokogiri (1.18.8) + nokogiri (1.18.9) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.18.8-arm64-darwin) + nokogiri (1.18.9-arm64-darwin) racc (~> 1.4) - nokogiri (1.18.8-x86_64-darwin) + nokogiri (1.18.9-x86_64-darwin) racc (~> 1.4) - nokogiri (1.18.8-x86_64-linux-gnu) + nokogiri (1.18.9-x86_64-linux-gnu) racc (~> 1.4) oauth (1.1.0) oauth-tty (~> 1.0, >= 1.0.1) @@ -785,6 +786,9 @@ GEM fugit (~> 1.8) globalid (>= 1.0.1) sidekiq (>= 6) + sidekiq_alive (2.5.0) + gserver (~> 0.0.1) + sidekiq (>= 5, < 9) signet (0.17.0) addressable (~> 2.8) faraday (>= 0.17.5, < 3.a) @@ -823,7 +827,7 @@ GEM stripe (8.5.0) telephone_number (1.4.20) test-prof (1.2.1) - thor (1.3.1) + thor (1.4.0) tilt (2.3.0) time_diff (0.3.0) activesupport @@ -1010,6 +1014,7 @@ DEPENDENCIES shoulda-matchers sidekiq (>= 7.3.1) sidekiq-cron (>= 1.12.0) + sidekiq_alive simplecov (= 0.17.1) slack-ruby-client (~> 2.5.2) spring diff --git a/VERSION_CW b/VERSION_CW index 4eba2a62e..fdc669880 100644 --- a/VERSION_CW +++ b/VERSION_CW @@ -1 +1 @@ -3.13.0 +4.4.0 diff --git a/VERSION_CWCTL b/VERSION_CWCTL index 944880fa1..18091983f 100644 --- a/VERSION_CWCTL +++ b/VERSION_CWCTL @@ -1 +1 @@ -3.2.0 +3.4.0 diff --git a/app/actions/contact_identify_action.rb b/app/actions/contact_identify_action.rb index a88d3535b..bcf5a93c3 100644 --- a/app/actions/contact_identify_action.rb +++ b/app/actions/contact_identify_action.rb @@ -6,6 +6,7 @@ # We don't want to update the name of the identified original contact. class ContactIdentifyAction + include UrlHelper pattr_initialize [:contact!, :params!, { retain_original_contact_name: false, discard_invalid_attrs: false }] def perform @@ -104,7 +105,14 @@ class ContactIdentifyAction # TODO: replace reject { |_k, v| v.blank? } with compact_blank when rails is upgraded @contact.discard_invalid_attrs if discard_invalid_attrs @contact.save! - Avatar::AvatarFromUrlJob.perform_later(@contact, params[:avatar_url]) if params[:avatar_url].present? && !@contact.avatar.attached? + enqueue_avatar_job + end + + def enqueue_avatar_job + return unless params[:avatar_url].present? && !@contact.avatar.attached? + return unless url_valid?(params[:avatar_url]) + + Avatar::AvatarFromUrlJob.perform_later(@contact, params[:avatar_url]) end def merge_contact(base_contact, merge_contact) diff --git a/app/controllers/api/v1/accounts/contacts_controller.rb b/app/controllers/api/v1/accounts/contacts_controller.rb index 4fbe50902..039786905 100644 --- a/app/controllers/api/v1/accounts/contacts_controller.rb +++ b/app/controllers/api/v1/accounts/contacts_controller.rb @@ -122,7 +122,7 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController def resolved_contacts return @resolved_contacts if @resolved_contacts - @resolved_contacts = Current.account.contacts.resolved_contacts + @resolved_contacts = Current.account.contacts.resolved_contacts(use_crm_v2: Current.account.feature_enabled?('crm_v2')) @resolved_contacts = @resolved_contacts.tagged_with(params[:labels], any: true) if params[:labels].present? @resolved_contacts diff --git a/app/controllers/api/v1/accounts/inboxes_controller.rb b/app/controllers/api/v1/accounts/inboxes_controller.rb index e7b3b197b..78b4b9e2f 100644 --- a/app/controllers/api/v1/accounts/inboxes_controller.rb +++ b/app/controllers/api/v1/accounts/inboxes_controller.rb @@ -69,6 +69,17 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController render status: :ok, json: { message: I18n.t('messages.inbox_deletetion_response') } end + def sync_templates + unless @inbox.channel.is_a?(Channel::Whatsapp) + return render status: :unprocessable_entity, json: { error: 'Template sync is only available for WhatsApp channels' } + end + + Channels::Whatsapp::TemplatesSyncJob.perform_later(@inbox.channel) + render status: :ok, json: { message: 'Template sync initiated successfully' } + rescue StandardError => e + render status: :internal_server_error, json: { error: e.message } + end + private def fetch_inbox diff --git a/app/controllers/microsoft_controller.rb b/app/controllers/microsoft_controller.rb index e6a12dafa..3071eac31 100644 --- a/app/controllers/microsoft_controller.rb +++ b/app/controllers/microsoft_controller.rb @@ -2,7 +2,7 @@ class MicrosoftController < ApplicationController after_action :set_version_header def identity_association - microsoft_indentity + microsoft_identity end private @@ -11,7 +11,7 @@ class MicrosoftController < ApplicationController response.headers['Content-Length'] = { associatedApplications: [{ applicationId: @identity_json }] }.to_json.length end - def microsoft_indentity + def microsoft_identity @identity_json = GlobalConfigService.load('AZURE_APP_ID', nil) end end diff --git a/app/controllers/webhooks/instagram_controller.rb b/app/controllers/webhooks/instagram_controller.rb index 3d46334ca..569c2524b 100644 --- a/app/controllers/webhooks/instagram_controller.rb +++ b/app/controllers/webhooks/instagram_controller.rb @@ -4,7 +4,16 @@ class Webhooks::InstagramController < ActionController::API def events Rails.logger.info('Instagram webhook received events') if params['object'].casecmp('instagram').zero? - ::Webhooks::InstagramEventsJob.perform_later(params.to_unsafe_hash[:entry]) + entry_params = params.to_unsafe_hash[:entry] + + if contains_echo_event?(entry_params) + # Add delay to prevent race condition where echo arrives before send message API completes + # This avoids duplicate messages when echo comes early during API processing + ::Webhooks::InstagramEventsJob.set(wait: 2.seconds).perform_later(entry_params) + else + ::Webhooks::InstagramEventsJob.perform_later(entry_params) + end + render json: :ok else Rails.logger.warn("Message is not received from the instagram webhook event: #{params['object']}") @@ -14,6 +23,16 @@ class Webhooks::InstagramController < ActionController::API private + def contains_echo_event?(entry_params) + return false unless entry_params.is_a?(Array) + + entry_params.any? do |entry| + # Check messaging array for echo events + messaging_events = entry[:messaging] || [] + messaging_events.any? { |messaging| messaging.dig(:message, :is_echo).present? } + end + end + def valid_token?(token) # Validates against both IG_VERIFY_TOKEN (Instagram channel via Facebook page) and # INSTAGRAM_VERIFY_TOKEN (Instagram channel via direct Instagram login) diff --git a/app/javascript/dashboard/api/inboxes.js b/app/javascript/dashboard/api/inboxes.js index 8c09791c8..361b9472f 100644 --- a/app/javascript/dashboard/api/inboxes.js +++ b/app/javascript/dashboard/api/inboxes.js @@ -28,6 +28,10 @@ class Inboxes extends CacheEnabledApiClient { agent_bot: botId, }); } + + syncTemplates(inboxId) { + return axios.post(`${this.url}/${inboxId}/sync_templates`); + } } export default new Inboxes(); diff --git a/app/javascript/dashboard/api/specs/inboxes.spec.js b/app/javascript/dashboard/api/specs/inboxes.spec.js index 628ce0f34..64ba44aea 100644 --- a/app/javascript/dashboard/api/specs/inboxes.spec.js +++ b/app/javascript/dashboard/api/specs/inboxes.spec.js @@ -12,6 +12,7 @@ describe('#InboxesAPI', () => { expect(inboxesAPI).toHaveProperty('getCampaigns'); expect(inboxesAPI).toHaveProperty('getAgentBot'); expect(inboxesAPI).toHaveProperty('setAgentBot'); + expect(inboxesAPI).toHaveProperty('syncTemplates'); }); describe('API calls', () => { @@ -40,5 +41,12 @@ describe('#InboxesAPI', () => { inboxesAPI.deleteInboxAvatar(2); expect(axiosMock.delete).toHaveBeenCalledWith('/api/v1/inboxes/2/avatar'); }); + + it('#syncTemplates', () => { + inboxesAPI.syncTemplates(2); + expect(axiosMock.post).toHaveBeenCalledWith( + '/api/v1/inboxes/2/sync_templates' + ); + }); }); }); diff --git a/app/javascript/dashboard/components-next/dropdown-menu/DropdownPrimitives.story.vue b/app/javascript/dashboard/components-next/dropdown-menu/DropdownPrimitives.story.vue index a174b1eea..397f45d93 100644 --- a/app/javascript/dashboard/components-next/dropdown-menu/DropdownPrimitives.story.vue +++ b/app/javascript/dashboard/components-next/dropdown-menu/DropdownPrimitives.story.vue @@ -6,7 +6,7 @@ import DropdownBody from './base/DropdownBody.vue'; import DropdownSection from './base/DropdownSection.vue'; import DropdownItem from './base/DropdownItem.vue'; import DropdownSeparator from './base/DropdownSeparator.vue'; -import WootSwitch from 'components/ui/Switch.vue'; +import ToggleSwitch from 'dashboard/components-next/switch/Switch.vue'; const currentUserAutoOffline = ref(false); @@ -61,7 +61,7 @@ const menuItems = ref([ {{ $t('SIDEBAR.SET_AUTO_OFFLINE.TEXT') }}
- +
diff --git a/app/javascript/dashboard/components-next/message/bubbles/Email/Index.vue b/app/javascript/dashboard/components-next/message/bubbles/Email/Index.vue index 2e03e97af..63b5f8eef 100644 --- a/app/javascript/dashboard/components-next/message/bubbles/Email/Index.vue +++ b/app/javascript/dashboard/components-next/message/bubbles/Email/Index.vue @@ -119,7 +119,13 @@ const handleSeeOriginal = () => { >