fix(call-attribution): resolve Ozonetel chain AgentNames to agent.id

Inbound transferred calls arrive with AgentName like 'RamaiahAdmin -> GlobalHealthX'. The webhook was persisting the raw chain string and leaving agentId null; the CDR enrichment cron then silently skipped 100% of rows because the bulk CDR keys on caller-leg UCID while the webhook stores monitorUCID — the join never matched.

- missed-call-webhook: split chain on ' -> ', take final handler,
  resolve via AgentLookupService (ozonetelAgentId + display name)
- cdr-enrichment: index CDR rows by both UCID and monitorUCID so
  the cron actually patches historical rows
- enrichment also parses chain in CDR AgentName as a second fallback
- spec: add CallerResolutionService + AgentLookupService mocks
This commit is contained in:
2026-04-15 18:55:00 +05:30
parent f375e7736c
commit 60d2329dd8
3 changed files with 67 additions and 3 deletions

View File

@@ -11,6 +11,8 @@ import { Test } from '@nestjs/testing';
import { ConfigService } from '@nestjs/config';
import { MissedCallWebhookController } from './missed-call-webhook.controller';
import { PlatformGraphqlService } from '../platform/platform-graphql.service';
import { AgentLookupService } from '../platform/agent-lookup.service';
import { CallerResolutionService } from '../caller/caller-resolution.service';
import {
WEBHOOK_INBOUND_ANSWERED,
WEBHOOK_INBOUND_MISSED,
@@ -48,11 +50,28 @@ describe('MissedCallWebhookController', () => {
}),
};
const mockCaller = {
resolve: jest.fn().mockResolvedValue({
leadId: '',
firstName: '',
lastName: '',
patientId: '',
isNew: true,
}),
};
const mockAgentLookup = {
resolveByOzonetelId: jest.fn().mockResolvedValue(null),
resolveByDisplayName: jest.fn().mockResolvedValue(null),
};
const module = await Test.createTestingModule({
controllers: [MissedCallWebhookController],
providers: [
{ provide: PlatformGraphqlService, useValue: mockPlatformGql },
{ provide: ConfigService, useValue: mockConfig },
{ provide: CallerResolutionService, useValue: mockCaller },
{ provide: AgentLookupService, useValue: mockAgentLookup },
],
}).compile();