feat: Ozonetel V3 dial endpoint, worklist query fixes

- Switch outbound dial to /CAServicesV3/mdlConnection.php (tbManualDial)
- Use both Apikey + Basic Auth headers matching Ozonetel toolbar pattern
- Auto-login agent before dial attempt
- Dial controller returns 502 (not 401) for Ozonetel errors to prevent session logout
- Fix worklist: remove non-existent callId from followUp query
- Fix worklist: use unquoted MISSED enum, remove callerNumber subfield issue
- Worklist controller resolves agent name from platform currentUser API

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-18 18:34:32 +05:30
parent 9688d5144e
commit a0df752cfd
3 changed files with 85 additions and 4 deletions

View File

@@ -1,11 +1,23 @@
import { Controller, Post, Body, Logger, HttpException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { OzonetelAgentService } from './ozonetel-agent.service';
@Controller('api/ozonetel')
export class OzonetelAgentController {
private readonly logger = new Logger(OzonetelAgentController.name);
private readonly defaultAgentId: string;
private readonly defaultAgentPassword: string;
constructor(private readonly ozonetelAgent: OzonetelAgentService) {}
private readonly defaultSipId: string;
constructor(
private readonly ozonetelAgent: OzonetelAgentService,
private readonly config: ConfigService,
) {
this.defaultAgentId = config.get<string>('OZONETEL_AGENT_ID') ?? 'agent3';
this.defaultAgentPassword = config.get<string>('OZONETEL_AGENT_PASSWORD') ?? '';
this.defaultSipId = config.get<string>('OZONETEL_SIP_ID') ?? '521814';
}
@Post('agent-login')
async agentLogin(
@@ -40,4 +52,34 @@ export class OzonetelAgentController {
);
}
}
@Post('dial')
async dial(
@Body() body: { phoneNumber: string; leadId?: string },
) {
if (!body.phoneNumber) {
throw new HttpException('phoneNumber required', 400);
}
this.logger.log(`Dial request: ${body.phoneNumber} (lead: ${body.leadId ?? 'none'})`);
try {
// Ensure agent is logged in before dialing
await this.ozonetelAgent.loginAgent({
agentId: this.defaultAgentId,
password: this.defaultAgentPassword,
phoneNumber: this.defaultSipId,
mode: 'blended',
});
const result = await this.ozonetelAgent.dialCustomer({
agentId: this.defaultAgentId,
customerNumber: body.phoneNumber,
});
return result;
} catch (error: any) {
const message = error.response?.data?.message ?? error.message ?? 'Dial failed';
throw new HttpException(message, 502);
}
}
}