From 8595a466425c81039632389879878fe2e07a3dfe Mon Sep 17 00:00:00 2001 From: Muhsin <12408980+muhsin-k@users.noreply.github.com> Date: Tue, 2 Jun 2026 22:01:23 +0400 Subject: [PATCH] chore: disable template messages --- app/services/app_store/review_builder.rb | 7 +++++- .../hook_execution_service.rb | 10 ++++---- .../services/app_store/review_builder_spec.rb | 18 ++++++++++++++ .../hook_execution_service_spec.rb | 24 +++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/app/services/app_store/review_builder.rb b/app/services/app_store/review_builder.rb index a42c16c09..f2e2cc143 100644 --- a/app/services/app_store/review_builder.rb +++ b/app/services/app_store/review_builder.rb @@ -113,7 +113,12 @@ class AppStore::ReviewBuilder def build_response_message return if response_id.blank? - return if @conversation.messages.exists?(source_id: response_id) + + message = @conversation.messages.find_by(source_id: response_id) + if message + message.update!(content: response_body, content_attributes: response_metadata, updated_at: response_created_at) + return + end @conversation.messages.create!( account_id: inbox.account_id, diff --git a/app/services/message_templates/hook_execution_service.rb b/app/services/message_templates/hook_execution_service.rb index 93f0447f3..3e232010a 100644 --- a/app/services/message_templates/hook_execution_service.rb +++ b/app/services/message_templates/hook_execution_service.rb @@ -21,8 +21,7 @@ class MessageTemplates::HookExecutionService def should_send_out_of_office_message? return false if conversation.campaign.present? - # should not send if its a tweet message - return false if conversation.tweet? + return false if review_inbox_or_tweet_conversation? # should not send for outbound messages return false unless message.incoming? # prevents sending out-of-office message if an agent has sent a message in last 5 minutes @@ -38,12 +37,15 @@ class MessageTemplates::HookExecutionService def should_send_greeting? return false if conversation.campaign.present? - # should not send if its a tweet message - return false if conversation.tweet? + return false if review_inbox_or_tweet_conversation? first_message_from_contact? && inbox.greeting_enabled? && inbox.greeting_message.present? end + def review_inbox_or_tweet_conversation? + conversation.tweet? || inbox.app_store? + end + def email_collect_was_sent? conversation.messages.where(content_type: 'input_email').present? end diff --git a/spec/services/app_store/review_builder_spec.rb b/spec/services/app_store/review_builder_spec.rb index 59f194345..5870f6766 100644 --- a/spec/services/app_store/review_builder_spec.rb +++ b/spec/services/app_store/review_builder_spec.rb @@ -69,5 +69,23 @@ RSpec.describe AppStore::ReviewBuilder do expect(inbox.conversations.last.messages.incoming.find_by(source_id: 'review-1').content).to include('Updated review body.') end + + it 'updates an existing developer response message when Apple returns an edited response' do + described_class.new(review_payload: review_payload, channel: channel).perform + updated_payload = review_payload.deep_dup + updated_payload['response']['attributes']['responseBody'] = 'Updated response.' + updated_payload['response']['attributes']['state'] = 'PENDING_PUBLISH' + updated_payload['response']['attributes']['lastModifiedDate'] = '2026-05-20T12:00:00-00:00' + + expect { described_class.new(review_payload: updated_payload, channel: channel).perform } + .not_to change(Message.where(inbox_id: inbox.id), :count) + + response_message = inbox.conversations.last.messages.outgoing.find_by(source_id: 'response-1') + expect(response_message.content).to eq('Updated response.') + expect(response_message.content_attributes['app_store']).to include( + 'response_state' => 'PENDING_PUBLISH', + 'response_last_modified_date' => '2026-05-20T12:00:00-00:00' + ) + end end end diff --git a/spec/services/message_templates/hook_execution_service_spec.rb b/spec/services/message_templates/hook_execution_service_spec.rb index e186227be..c8c27b1b7 100644 --- a/spec/services/message_templates/hook_execution_service_spec.rb +++ b/spec/services/message_templates/hook_execution_service_spec.rb @@ -270,4 +270,28 @@ describe MessageTemplates::HookExecutionService do expect(out_of_office_service).not_to receive(:perform) end end + + context 'when the inbox is an App Store Reviews channel' do + let(:channel) { create(:channel_app_store) } + let(:inbox) { channel.inbox } + let(:conversation) { create(:conversation, inbox: inbox, account: channel.account) } + + it 'does not fire the greeting template even when greeting_enabled is true' do + inbox.update!(greeting_enabled: true, greeting_message: 'Thanks for reviewing!') + allow(MessageTemplates::Template::Greeting).to receive(:new) + + create(:message, conversation: conversation, account: conversation.account) + + expect(MessageTemplates::Template::Greeting).not_to have_received(:new) + end + + it 'does not fire the out-of-office template even when configured' do + inbox.update!(working_hours_enabled: true, out_of_office_message: 'Back tomorrow') + allow(MessageTemplates::Template::OutOfOffice).to receive(:new) + + create(:message, conversation: conversation, account: conversation.account) + + expect(MessageTemplates::Template::OutOfOffice).not_to have_received(:new) + end + end end