feat: add assignment service

This commit is contained in:
Tanmay Sharma
2025-08-28 17:03:11 +07:00
parent 472493b9af
commit eacfa2e19a
23 changed files with 1153 additions and 10 deletions
@@ -14,7 +14,13 @@ module AutoAssignmentHandler
return unless conversation_status_changed_to_open?
return unless should_run_auto_assignment?
::AutoAssignment::AgentAssignmentService.new(conversation: self, allowed_agent_ids: inbox.member_ids_with_assignment_capacity).perform
if inbox.auto_assignment_enabled?
# Use new assignment system
AutoAssignment::AssignmentJob.perform_later(inbox_id: inbox.id)
else
# Use legacy assignment system
AutoAssignment::AgentAssignmentService.new(conversation: self, allowed_agent_ids: inbox.member_ids_with_assignment_capacity).perform
end
end
def should_run_auto_assignment?
@@ -0,0 +1,28 @@
module InboxAgentAvailability
extend ActiveSupport::Concern
def available_agents
online_agent_ids = fetch_online_agent_ids
return inbox_members.none if online_agent_ids.empty?
inbox_members
.joins(:user)
.where(users: { id: online_agent_ids })
.includes(:user)
end
def member_ids_with_assignment_capacity
member_ids
end
private
def fetch_online_agent_ids
OnlineStatusTracker.get_available_users(account_id)
.select { |_key, value| value.eql?('online') }
.keys
.map(&:to_i)
end
end
InboxAgentAvailability.prepend_mod_with('InboxAgentAvailability')
+5
View File
@@ -44,6 +44,7 @@ class Inbox < ApplicationRecord
include Avatarable
include OutOfOffisable
include AccountCacheRevalidator
include InboxAgentAvailability
# Not allowing characters:
validates :name, presence: true
@@ -190,6 +191,10 @@ class Inbox < ApplicationRecord
members.ids
end
def auto_assignment_enabled?
account.feature_enabled?('assignment_v2') && assignment_policy.present? && assignment_policy.enabled?
end
private
def default_name_for_blank_name