chore: disable template messages
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user