fix: Respect messaging window constraints for auto-resolve messages (#11757)

This commit is contained in:
Muhsin Keloth
2025-06-19 21:30:49 +05:30
committed by GitHub
parent b683973e79
commit 578e2ee8db
2 changed files with 20 additions and 1 deletions

View File

@@ -4,8 +4,10 @@ class MessageTemplates::Template::AutoResolve
def perform
return if conversation.account.auto_resolve_message.blank?
ActiveRecord::Base.transaction do
if within_messaging_window?
conversation.messages.create!(auto_resolve_message_params)
else
create_auto_resolve_not_sent_activity_message
end
end
@@ -14,6 +16,21 @@ class MessageTemplates::Template::AutoResolve
delegate :contact, :account, to: :conversation
delegate :inbox, to: :message
def within_messaging_window?
conversation.can_reply?
end
def create_auto_resolve_not_sent_activity_message
content = I18n.t('conversations.activity.auto_resolve.not_sent_due_to_messaging_window')
activity_message_params = {
account_id: conversation.account_id,
inbox_id: conversation.inbox_id,
message_type: :activity,
content: content
}
::Conversations::ActivityMessageJob.perform_later(conversation, activity_message_params) if content
end
def auto_resolve_message_params
{
account_id: @conversation.account_id,

View File

@@ -196,6 +196,8 @@ en:
issue_unlinked: 'Linear issue %{issue_id} was unlinked by %{user_name}'
csat:
not_sent_due_to_messaging_window: 'CSAT survey not sent due to outgoing message restrictions'
auto_resolve:
not_sent_due_to_messaging_window: 'Auto-resolve message not sent due to outgoing message restrictions'
muted: '%{user_name} has muted the conversation'
unmuted: '%{user_name} has unmuted the conversation'
auto_resolution_message: 'Resolving the conversation as it has been inactive for a while. Please start a new conversation if you need further assistance.'