mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-04-11 18:08:16 +00:00
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { Controller, Get, Query, Logger, Header } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
|
|
@Controller('kookoo')
|
|
export class KookooIvrController {
|
|
private readonly logger = new Logger(KookooIvrController.name);
|
|
private readonly sipId: string;
|
|
private readonly callerId: string;
|
|
|
|
constructor(private config: ConfigService) {
|
|
this.sipId = process.env.OZONETEL_SIP_ID ?? '523590';
|
|
this.callerId = process.env.OZONETEL_DID ?? '918041763265';
|
|
}
|
|
|
|
@Get('ivr')
|
|
@Header('Content-Type', 'application/xml')
|
|
handleIvr(@Query() query: Record<string, any>): string {
|
|
const event = query.event ?? '';
|
|
const sid = query.sid ?? '';
|
|
const cid = query.cid ?? '';
|
|
const status = query.status ?? '';
|
|
|
|
this.logger.log(
|
|
`Kookoo IVR: event=${event} sid=${sid} cid=${cid} status=${status}`,
|
|
);
|
|
|
|
// New outbound call — customer answered, put them in a conference room
|
|
// The room ID is based on the call SID so we can join from the browser
|
|
if (event === 'NewCall') {
|
|
this.logger.log(
|
|
`Customer ${cid} answered — dialing DID ${this.callerId} to route to agent`,
|
|
);
|
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
<response>
|
|
<dial record="true" timeout="30" moh="ring">${this.callerId}</dial>
|
|
</response>`;
|
|
}
|
|
|
|
// Conference event — user left with #
|
|
if (event === 'conference' || event === 'Conference') {
|
|
this.logger.log(`Conference event: status=${status}`);
|
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
<response>
|
|
<hangup/>
|
|
</response>`;
|
|
}
|
|
|
|
// Dial or Disconnect
|
|
this.logger.log(`Call ended: event=${event}`);
|
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
<response>
|
|
<hangup/>
|
|
</response>`;
|
|
}
|
|
}
|