feat: transcription fix + SLA write-back + real-time supervisor events

- Deepgram: multichannel=true + language=multi (captures both speakers, multilingual)
- LLM speaker identification (agent vs customer from conversational cues)
- Removed summarize=v2 (incompatible with multilingual)
- SLA computation on call creation (lead.createdAt → call.startedAt elapsed %)
- WebSocket: supervisor room + call:created broadcast for real-time updates
- Maint: clear-analysis-cache endpoint + scanKeys/deleteCache on SessionService
- AI chat: rules-engine context routing with dedicated system prompt

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-01 16:59:23 +05:30
parent b8556cf440
commit 5e3ccbd040
8 changed files with 461 additions and 33 deletions

View File

@@ -35,6 +35,20 @@ export class CallEventsGateway {
this.server.to(room).emit('call:incoming', event);
}
// Broadcast to supervisors when a new call record is created
broadcastCallCreated(callData: any) {
this.logger.log('Broadcasting call:created to supervisor room');
this.server.to('supervisor').emit('call:created', callData);
}
// Supervisor registers to receive real-time updates
@SubscribeMessage('supervisor:register')
handleSupervisorRegister(@ConnectedSocket() client: Socket) {
client.join('supervisor');
this.logger.log(`Supervisor registered (socket: ${client.id})`);
client.emit('supervisor:registered', { room: 'supervisor' });
}
// Agent registers when they open the Call Desk page
@SubscribeMessage('agent:register')
handleAgentRegister(

View File

@@ -167,7 +167,24 @@ export class CallEventsService {
`Processing disposition: ${payload.disposition} for call ${payload.callSid}`,
);
// 1. Create Call record in platform
// 1. Compute SLA % if lead is linked
let sla: number | undefined;
if (payload.leadId && payload.startedAt) {
try {
const lead = await this.platform.findLeadById(payload.leadId);
if (lead?.createdAt) {
const leadCreated = new Date(lead.createdAt).getTime();
const callStarted = new Date(payload.startedAt).getTime();
const elapsedMin = Math.max(0, (callStarted - leadCreated) / 60000);
const slaThresholdMin = 1440; // Default 24h; missed calls use 720 but this is a completed call
sla = Math.round((elapsedMin / slaThresholdMin) * 100);
}
} catch {
// SLA computation is best-effort
}
}
// 2. Create Call record in platform
try {
await this.platform.createCall({
callDirection: 'INBOUND',
@@ -187,8 +204,11 @@ export class CallEventsService {
disposition: payload.disposition,
callNotes: payload.notes || undefined,
leadId: payload.leadId || undefined,
sla,
});
this.logger.log(`Call record created for ${payload.callSid}`);
this.logger.log(`Call record created for ${payload.callSid} (SLA: ${sla ?? 'N/A'}%)`);
// Notify supervisors in real-time
this.gateway.broadcastCallCreated({ callSid: payload.callSid, agentName: payload.agentName, disposition: payload.disposition });
} catch (error) {
this.logger.error(`Failed to create call record: ${error}`);
}