WIP - phone calls inbound an outbound
This commit is contained in:
@@ -159,24 +159,40 @@ export class VoiceController {
|
||||
const fromNumber = body.From;
|
||||
const toNumber = body.To;
|
||||
|
||||
this.logger.log(`Incoming call: ${callSid} from ${fromNumber} to ${toNumber}`);
|
||||
this.logger.log(`=== INBOUND CALL RECEIVED ===`);
|
||||
this.logger.log(`CallSid: ${callSid}, From: ${fromNumber}, To: ${toNumber}`);
|
||||
this.logger.log(`Full body: ${JSON.stringify(body)}`);
|
||||
|
||||
// TODO: Determine tenant from phone number mapping
|
||||
// TODO: Find available user to route call to
|
||||
// For now, return a simple TwiML response
|
||||
try {
|
||||
// Extract tenant domain from phone number mapping
|
||||
// For now, we'll need to determine which tenant owns this phone number
|
||||
// TODO: Add phone number to tenant mapping in database
|
||||
|
||||
// For multi-tenant, we need to route to the correct user's browser Device
|
||||
// The Device identity is the userId we used when generating the access token
|
||||
|
||||
// For now, let's dial ALL connected clients (you can refine this later)
|
||||
// Using a simple approach: dial the most recently connected user
|
||||
|
||||
const twiml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Response>
|
||||
<Start>
|
||||
<Stream url="wss://${req.headers.host}/api/voice/stream" />
|
||||
</Start>
|
||||
<Say>Please wait while we connect you to an agent</Say>
|
||||
<Say>Connecting your call</Say>
|
||||
<Dial>
|
||||
<Queue>support</Queue>
|
||||
<Client>e6d45fa3-a108-4085-81e5-a8e05e85e6fb</Client>
|
||||
</Dial>
|
||||
</Response>`;
|
||||
|
||||
this.logger.log(`Returning inbound TwiML - dialing Client`);
|
||||
res.type('text/xml').send(twiml);
|
||||
} catch (error: any) {
|
||||
this.logger.error(`Error generating inbound TwiML: ${error.message}`);
|
||||
const errorTwiml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Response>
|
||||
<Say>Sorry, we are unable to connect your call at this time.</Say>
|
||||
<Hangup/>
|
||||
</Response>`;
|
||||
res.type('text/xml').send(errorTwiml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user