busy-lion-12288
08/25/2025, 6:06 PMtall-airline-16756
08/25/2025, 6:06 PMtall-airline-16756
08/25/2025, 6:06 PMbusy-lion-12288
08/25/2025, 6:07 PMtall-airline-16756
08/25/2025, 6:07 PMbusy-lion-12288
08/25/2025, 6:08 PMbash
_# What's running on your server:_
redis-server _# Database for storing call info_
livekit-server-new _# Main communication hub_
sip-service-new _# Converts phone calls to web calls_
What each does:
- Redis: Stores information about calls, like a notebook
- LiveKit Server: Manages video/audio rooms (like Zoom rooms)
- SIP Service: Translates between phone calls and web calls
---
### 2. 📞 SIP Trunks (Phone Line Connections)
Each phone number gets its own "trunk" (think: dedicated phone line):
:telephone_receiver: Sales-Trunk → +15105550100
:telephone_receiver: Support-Trunk → +15105550101
:telephone_receiver: Manager-Trunk → +15105550102
:telephone_receiver: Emergency-Trunk → +15105550103
Why separate trunks?
- Each number can have different settings
- No conflicts between different agents
- Easy to manage and modify
---
### 3. 📋 Dispatch Rules (Call Routing)
Each trunk has a "rule" that says where to send the call:
+15105550100 (Sales Trunk) → Rule → "sales-room"
+15105550101 (Support Trunk) → Rule → "support-room"
+15105550102 (Manager Trunk) → Rule → "manager-room"
+15105550103 (Emergency Trunk) → Rule → "emergency-room"
Think of it like a receptionist:
- "Oh, you called Sales? Let me connect you to the sales-room"
- "You called Support? Right this way to the support-room"
---
### 4. 🤖 AI Agents (The Smart Assistants)
Each room gets a specific AI agent:
javascript
_// Agent looks at room name and knows who they are_
const agentConfig = {
"sales-room": {
agentId: "sales-agent-001",
role: "Help customers buy products",
permissions: ["transfer", "record", "access_pricing"],
personality: "Friendly and persuasive"
},
"support-room": {
agentId: "support-agent-002",
role: "Help customers with problems",
permissions: ["diagnose", "escalate", "create_tickets"],
personality: "Patient and technical"
}
}
---
## 🔄 Step-by-Step: What Happens During a Call
### Scenario: Customer calls Sales (+15105550100)
STEP 1: PHONE CALL ARRIVES
:iphone: Customer dials +15105550100
:cloud: Twilio receives the call
:outbox_tray: Twilio sends call to your server at 13.223.46.6:5060
STEP 2: SIP SERVICE PROCESSES
:desktop_computer: SIP service receives the call on port 5060
:question: "Which trunk handles +15105550100?"
:white_check_mark: Answer: "Sales-Trunk (ST_SJRMiJwDtHpE)"
STEP 3: DISPATCH RULE TRIGGERS
:clipboard: "What should I do with calls to Sales-Trunk?"
:white_check_mark: Answer: "Send them to 'sales-room'"
STEP 4: ROOM CREATION
:video_game: LiveKit creates/opens room called "sales-room"
:headphones: Sets up audio channels for the conversation
STEP 5: AGENT JOINS
:robot_face: AI Sales Agent connects to "sales-room"
:brain: Agent sees room name = "sales-room"
:closed_lock_with_key: Agent authenticates: "I'm sales-agent-001"
:briefcase: Agent loads sales skills and permissions
STEP 6: CONVERSATION BEGINS
:iphone: Customer's voice → Phone → SIP → LiveKit → Agent
:robot_face: Agent's voice → LiveKit → SIP → Phone → Customer
:speech_balloon: They can now talk naturally!
STEP 7: DURING THE CALL
:dart: Agent can:
• Access customer database
• Process payments
• Transfer to manager if needed
• Record call for quality
• All based on their permissions!
---
## 🎛️ Configuration Files Explained
### livekit-config.yaml (The Main Hub Settings)
yaml
port: 7880 _# Where LiveKit listens_
keys: _# Security keys_
devkey: secret _# Password for services to connect_
redis: _# Where to store data_
address: localhost:6379 _# Redis database location_
### sip-config.yaml (Phone System Settings)
yaml
api_key: devkey _# How to talk to LiveKit_
ws_url: ws://localhost:7880 _# Where LiveKit is located_
sip_port: 5060 _# Where phone calls arrive_
external_ip: "13.223.46.6" _# Your public server address_
rtp_port: 10000-20000 _# Audio/video data ports_
---
## 🧪 How We Created Everything
### The Magic Script: create-separate-trunks-and-rules.sh
This one script does everything automatically:
bash
_# 1. Creates 4 trunks (one per phone number)_
./lk sip inbound create --name "Sales-Trunk" --numbers "+15105550100"
./lk sip inbound create --name "Support-Trunk" --numbers "+15105550101"
_# ... and so on_
_# 2. Creates 4 dispatch rules (one per trunk → room)_
./lk sip dispatch create --direct "sales-room" --trunks "ST_SalesID"
./lk sip dispatch create --direct "support-room" --trunks "ST_SupportID"
_# ... and so on_
Result:
- 4 phone numbers ✅
- 4 separate rooms ✅
- 4 different agents ✅
- All connected properly ✅
is this good?busy-lion-12288
08/25/2025, 6:08 PMtall-airline-16756
08/25/2025, 6:09 PMbusy-lion-12288
08/25/2025, 6:10 PMbusy-lion-12288
08/25/2025, 6:11 PMtall-airline-16756
08/25/2025, 6:12 PM./lk sip inbound create --name "Trunk-Name" --numbers "+PhoneNumber" for each phone number. This way, each number gets its own trunk.
2. Create Dispatch Rules: Use ./lk sip dispatch create --direct "room-name" --trunks "Trunk-ID" to send calls from each trunk to the right room. Just swap out "room-name" and "Trunk-ID" with your actual room and trunk info.
Make sure that:
• Each trunk matches the correct phone number.
• Your dispatch rules are set up to send calls to the right rooms (like "sales-room" or "support-room").
If anything feels unclear or you hit a snag, just give me a shout—I’m here to help!
Sources: cmd/lk/sip.go | packages/livekit-server-sdk/src/SipClient.ts | livekit-protocol/src/livekit.rs | SIP overview | LiveKit Docs | sip/sip_test.gobusy-lion-12288
08/25/2025, 7:00 PMbusy-lion-12288
08/25/2025, 7:00 PMtall-airline-16756
08/25/2025, 7:00 PMtall-airline-16756
08/25/2025, 7:00 PMbusy-lion-12288
08/25/2025, 7:03 PMtall-airline-16756
08/25/2025, 7:04 PMpstn.twilio.com.
2. Configure Origination URL: Set the origination URL to your LiveKit SIP URI (something like sip:your-livekit-server:5060;transport=tcp).
3. Associate Phone Number: Link your Twilio phone number to the SIP trunk by associating the phone number SID with it.
4. Set Up SIP Credentials: Create a SIP credentials list in Twilio with a username and password, then connect it to your SIP trunk for authentication.
After that, just make sure your LiveKit SIP service is ready to accept calls from Twilio by matching those SIP credentials and pointing to the same Redis instance for session/state sharing. If you want me to walk you through any part or have questions, just give me a shout—I’m here to help!
Sources: Create and configure a Twilio SIP trunk | LiveKit Docs | .env.example | Inbound calls with Twilio Voice | LiveKit Docs