This guide details the complete call flow from the browser to Twilio conference.
Step 1: Browser Initiates Call
The browser uses the Twilio Voice SDK to initiate a call:
const device = new Twilio.Device(token, {
codecPreferences: ['opus', 'pcmu'],
});
const params = {
To: '+14155551234',
From: '+14155559876',
workspaceId: 'ws_abc123',
};
const connection = device.connect(params);
Step 2: TwiML Webhook
Twilio sends a webhook to your server:
Request parameters:
CallSid - Unique call identifier
To - Called phone number
From - Caller phone number
AccountSid - Twilio account ID
Step 3: Backend Processing
The backend performs:
- Validate request - Verify Twilio signature
- Create conference - Generate unique conference name
- Store mapping - Save callSid → conferenceName
- Generate TwiML - Return conference XML
// Generate TwiML response
const twiml = `
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Conference startConferenceOnEnter="true"
endConferenceOnExit="false"
participantLabel="agent">
${conferenceName}
</Conference>
</Dial>
</Response>
`;
Step 4: Customer Dial-Out
The backend immediately dials the customer:
await twilio.calls.create({
url: `https://your-domain.com/v1/voice/conference-join?conference=${conferenceName}`,
to: customerNumber,
from: callerId,
statusCallback: `https://your-domain.com/v1/voice/status`,
statusCallbackEvent: ['completed', 'no-answer', 'busy', 'failed'],
});
The conference join TwiML:
<Response>
<Dial>
<Conference endConferenceOnExit="true" label="customer">
${conferenceName}
</Conference>
</Dial>
</Response>
Complete Flow Diagram
Browser Twilio Backend
| | |
| device.connect() | |
|────────────────────────>│ |
| | POST /v1/voice/twiml |
| |<──────────────────────|
| | |
| <Conference TwiML> | |
|<────────────────────────| |
| | |
| [Agent joins conf] | |
| | |
| | [Dial customer] |
| |<──────────────────────|
| | |
| | POST /v1/voice/ |
| | conference-join |
| |<──────────────────────|
| | |
| [Customer joins] | |
| | |
| [Active call] | |
Status Callbacks
Monitor call status via webhooks:
| Event | Description |
|---|
initiated | Call created |
ringing | Call is ringing |
answered | Call was answered |
completed | Call ended normally |
no-answer | No answer |
busy | Line busy |
failed | Call failed |
Always implement proper error handling and logging for TwiML webhooks. Failed
webhooks result in call failures.