feat(leads): sidecar polling service for auto-assigning unassigned leads

Replaces the untrusted platform function path (SDK's lead-auto-assign
was written but never deployed to either workspace — all leads created
after seeding are orphan).

Polls every 60s:
  1. Fetch up to 100 unassigned leads (assignedAgent empty or null)
  2. Fetch platform Agents whose live SupervisorService state is
     ready/calling/in-call/acw (skip offline/break/training/unknown)
  3. Build open-lead count per agent (single paginated query)
  4. Assign each unassigned lead to the least-loaded active agent —
     writes agent.name into lead.assignedAgent to match the worklist
     filter (assignedAgent: { eq: agentName })

Catches every lead-creation path: CSV import, enquiry form,
missed-call webhook, widget, livekit. No platform changes needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-15 11:23:53 +05:30
parent 98f5bc0347
commit 34e053204f
3 changed files with 195 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import { ConfigThemeModule } from './config/config-theme.module';
import { WidgetModule } from './widget/widget.module';
import { TeamModule } from './team/team.module';
import { MasterdataModule } from './masterdata/masterdata.module';
import { LeadsModule } from './leads/leads.module';
import { TelephonyRegistrationService } from './telephony-registration.service';
@Module({
@@ -51,6 +52,7 @@ import { TelephonyRegistrationService } from './telephony-registration.service';
WidgetModule,
TeamModule,
MasterdataModule,
LeadsModule,
],
providers: [TelephonyRegistrationService],
})