bored-australia-85761
10/24/2025, 9:13 AMtall-airline-16756
10/24/2025, 9:13 AMtall-airline-16756
10/24/2025, 9:14 AMimport { SipClient } from 'livekit-server-sdk';
const sipClient = new SipClient(LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
// Create or retrieve an inbound trunk
const trunkName = 'inbound-trunk';
const trunks = await sipClient.listSipInboundTrunk();
let trunk = trunks.find(t => t.name === trunkName);
if (!trunk) {
trunk = await sipClient.createSipInboundTrunk(trunkName, [TWILIO_PHONE_NUMBER], {
auth_username: TWILIO_SIP_USERNAME,
auth_password: TWILIO_SIP_PASSWORD,
});
}
// Create or retrieve a dispatch rule
const dispatchRuleName = 'inbound-dispatch-rule';
const dispatchRules = await sipClient.listSipDispatchRule();
let dispatchRule = dispatchRules.find(r => r.name === dispatchRuleName);
if (!dispatchRule) {
dispatchRule = await sipClient.createSipDispatchRule({
type: 'individual',
roomPrefix: 'call',
}, {
name: dispatchRuleName,
trunkIds: [trunk.sipTrunkId],
});
}
This snippet helps you set up an inbound trunk and a dispatch rule programmatically. If you prefer, you can also achieve similar setups using Python or JSON configuration. Please feel free to reach out if you have any questions or need a hand with anything else—I’m here to help!
Sources: src/setup-livekit.ts | Creating SIP Inbound Trunks and Dispatch Rules with Python SDK | SIP inbound trunk | LiveKit Docs | complex-agents/ivr-agent/README.md