diff --git a/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb b/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb index 9602b073d..7e00ef011 100644 --- a/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb +++ b/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb @@ -112,19 +112,18 @@ class Api::V1::Accounts::Captain::AssistantsController < Api::V1::Accounts::Base permitted[:guardrails] = params[:assistant][:guardrails] if params[:assistant].key?(:guardrails) - # The audience is a recursive condition tree that strong params can't whitelist by shape; - # route it through separately. Validity is enforced by Captain::AudienceValidator. permit_audience_config(permitted) permitted end + # The audience is a recursive condition tree that strong params can't whitelist by shape; + # pass it through raw and let Captain::AudienceValidator enforce validity. def permit_audience_config(permitted) config = params[:assistant][:config] - return unless config.respond_to?(:key?) && config.key?(:audience) + return unless config.try(:key?, :audience) audience = config[:audience] - permitted[:config] ||= ActionController::Parameters.new.permit! permitted[:config][:audience] = audience.respond_to?(:permit!) ? audience.permit!.to_h : audience end diff --git a/enterprise/app/services/enterprise/message_templates/hook_execution_service.rb b/enterprise/app/services/enterprise/message_templates/hook_execution_service.rb index ac1c9e0c3..0f377ada0 100644 --- a/enterprise/app/services/enterprise/message_templates/hook_execution_service.rb +++ b/enterprise/app/services/enterprise/message_templates/hook_execution_service.rb @@ -79,12 +79,8 @@ module Enterprise::MessageTemplates::HookExecutionService conversation.pending? && captain_should_engage? end - # True only when the inbox has a Captain assistant that should engage this conversation now — - # i.e. the contact is within the audience AND the assistant is on-schedule. Otherwise the - # conversation falls back to normal human handling (greeting/OOO templates fire, Captain silent). def captain_should_engage? - inbox.respond_to?(:captain_assistant) && - inbox.captain_assistant.present? && - inbox.captain_assistant.engages?(conversation.contact, conversation) + assistant = inbox.captain_assistant + assistant.present? && assistant.engages?(conversation.contact, conversation) end end