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 { 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 ` ${this.callerId} `; } // Conference event — user left with # if (event === 'conference' || event === 'Conference') { this.logger.log(`Conference event: status=${status}`); return ` `; } // Dial or Disconnect this.logger.log(`Call ended: event=${event}`); return ` `; } }