refactor(captain): tidy comments and naming in assistant engagement code

This commit is contained in:
Pranav
2026-07-14 16:40:17 -07:00
parent 6bbb763d4a
commit 0e2d577d43
2 changed files with 6 additions and 12 deletions
+3 -9
View File
@@ -58,30 +58,24 @@ class Captain::Assistant < ApplicationRecord
name
end
# Whether this assistant should engage the given conversation right now — combines the audience
# filter (who) and the schedule (when).
def engages?(contact, conversation)
responds_to_audience?(contact, conversation) && available_now?(conversation)
end
# Whether this assistant should engage the given contact, based on its audience filter.
# No audience configured => responds to everyone (back-compat).
def responds_to_audience?(contact, conversation)
return true if config['audience'].blank?
Captain::AudienceMatcher.new(config['audience']).matches?(contact, conversation)
end
# Whether the assistant is on duty for this conversation based on the response window.
# Inboxes without business hours configured are always covered (fail open).
def available_now?(conversation)
window = config['response_window']
return true if window.blank? || window == 'always'
response_window = config['response_window']
return true if response_window.blank? || response_window == 'always'
inbox = conversation.inbox
return true unless inbox.working_hours_enabled?
window == 'business_hours' ? !inbox.out_of_office? : inbox.out_of_office?
response_window == 'business_hours' ? !inbox.out_of_office? : inbox.out_of_office?
end
def available_agent_tools
+3 -3
View File
@@ -16,11 +16,11 @@ module Enterprise::Message
private
def reopen_resolved_conversation
captain_assistant = conversation.inbox.captain_assistant
assistant = conversation.inbox.captain_assistant
return super if captain_assistant.blank?
return super if assistant.blank?
return conversation.open! unless captain_assistant.engages?(conversation.contact, conversation)
return conversation.open! unless assistant.engages?(conversation.contact, conversation)
super
end