WIP - some progress making phone calls from softphone, we need https to test

This commit is contained in:
Francisco Gaona
2026-01-03 10:06:27 +01:00
parent 715934f157
commit fff1718478
9 changed files with 518 additions and 879 deletions

View File

@@ -49,6 +49,25 @@ export class VoiceController {
};
}
/**
* Generate Twilio access token for browser client
*/
@Get('token')
@UseGuards(JwtAuthGuard)
async getAccessToken(
@Req() req: any,
@TenantId() tenantId: string,
) {
const userId = req.user?.userId || req.user?.sub;
const token = await this.voiceService.generateAccessToken(tenantId, userId);
return {
success: true,
data: { token },
};
}
/**
* Get call history
*/
@@ -73,19 +92,23 @@ export class VoiceController {
}
/**
* TwiML for outbound calls
* TwiML for outbound calls from browser (Twilio Device)
*/
@Post('twiml/outbound')
async outboundTwiml(@Req() req: FastifyRequest, @Res() res: FastifyReply) {
const body = req.body as any;
const to = body.To;
this.logger.log(`Outbound call to: ${to}`);
// TwiML to dial the number and setup media stream for OpenAI
const twiml = `<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Start>
<Stream url="wss://${req.headers.host}/api/voice/stream" />
</Start>
<Say>Connecting your call</Say>
<Dial>
<Number>${(req.body as any).To}</Number>
</Dial>
<Dial>${to}</Dial>
</Response>`;
res.type('text/xml').send(twiml);