import { Controller, Get, Query, Logger, Header } from '@nestjs/common'; import { TelephonyConfigService } from '../config/telephony-config.service'; @Controller('kookoo') export class KookooIvrController { private readonly logger = new Logger(KookooIvrController.name); constructor(private telephony: TelephonyConfigService) {} private get sipId(): string { return this.telephony.getConfig().ozonetel.sipId || '523590'; } private get callerId(): string { return this.telephony.getConfig().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 ` `; } }