fix: captain talking over support agent (#13673)
This commit is contained in:
40
enterprise/app/models/enterprise/message.rb
Normal file
40
enterprise/app/models/enterprise/message.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
module Enterprise::Message
|
||||
private
|
||||
|
||||
def mark_pending_conversation_as_open_for_human_response
|
||||
return unless captain_pending_conversation?
|
||||
return unless human_response?
|
||||
return if private?
|
||||
|
||||
previous_user = Current.user
|
||||
previous_executed_by = Current.executed_by
|
||||
Current.user = nil
|
||||
Current.executed_by = nil
|
||||
|
||||
begin
|
||||
conversation.open!
|
||||
return unless conversation.saved_change_to_status?
|
||||
|
||||
create_captain_auto_open_activity_message
|
||||
ensure
|
||||
Current.user = previous_user
|
||||
Current.executed_by = previous_executed_by
|
||||
end
|
||||
end
|
||||
|
||||
def captain_pending_conversation?
|
||||
return false unless conversation.pending?
|
||||
|
||||
::CaptainInbox.exists?(inbox_id: conversation.inbox_id)
|
||||
end
|
||||
|
||||
def create_captain_auto_open_activity_message
|
||||
::Conversations::ActivityMessageJob.perform_later(
|
||||
conversation,
|
||||
account_id: conversation.account_id,
|
||||
inbox_id: conversation.inbox_id,
|
||||
message_type: :activity,
|
||||
content: I18n.t('conversations.activity.captain.auto_opened_after_agent_reply', locale: conversation.account.locale)
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user