Add a temporary `captain_disable_auto_resolve` boolean setting on accounts to prevent Captain from resolving conversations. Guards both the scheduled resolution job and the assistant's resolve tool. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
35 lines
1.1 KiB
Ruby
35 lines
1.1 KiB
Ruby
class Captain::InboxPendingConversationsResolutionJob < ApplicationJob
|
|
queue_as :low
|
|
|
|
def perform(inbox)
|
|
return if inbox.account.captain_disable_auto_resolve
|
|
|
|
Current.executed_by = inbox.captain_assistant
|
|
|
|
resolvable_conversations = inbox.conversations.pending.where('last_activity_at < ? ', Time.now.utc - 1.hour).limit(Limits::BULK_ACTIONS_LIMIT)
|
|
resolvable_conversations.each do |conversation|
|
|
create_outgoing_message(conversation, inbox)
|
|
conversation.resolved!
|
|
end
|
|
ensure
|
|
Current.reset
|
|
end
|
|
|
|
private
|
|
|
|
def create_outgoing_message(conversation, inbox)
|
|
I18n.with_locale(inbox.account.locale) do
|
|
resolution_message = inbox.captain_assistant.config['resolution_message']
|
|
conversation.messages.create!(
|
|
{
|
|
message_type: :outgoing,
|
|
account_id: conversation.account_id,
|
|
inbox_id: conversation.inbox_id,
|
|
content: resolution_message.presence || I18n.t('conversations.activity.auto_resolution_message'),
|
|
sender: inbox.captain_assistant
|
|
}
|
|
)
|
|
end
|
|
end
|
|
end
|