Appearance
LiveKit Outbound
Route outbound calls from LiveKit onto the PSTN via SignalWire.
How It Works
- LiveKit initiates a SIP call to a SignalWire SIP Address
- SignalWire executes the assigned SWML script
- The
connectverb bridges the call to the destination PSTN number - The callee receives a call from your SignalWire phone number
SWML Script
yaml
version: 1.0.0
sections:
main:
- connect:
answer_on_bridge: true
from: "+1XXXXXXXXXX"
to: "%{call.to.replace(/^sip:/i, '').replace(/@.*/, '')}"- Replace
+1XXXXXXXXXXwith your SignalWire outbound phone number - The
toexpression strips the SIP prefix and domain from the dialed address, extracting the raw E.164 number
Setup Steps
1. Create the SWML Script
Create a SWML script in your SignalWire Dashboard using the configuration above.
2. Add a SIP Address
In SignalWire:
- Go to SIP → SIP Addresses
- Create a new SIP Address
- Assign the SWML script to it
- Note the unique SIP domain (e.g.,
your-space.sip.signalwire.com)
3. Get Auth Credentials
Contact SignalWire Support to obtain the app password for your SIP Address. This is required for LiveKit's trunk configuration.
4. Create LiveKit Outbound SIP Trunk
In LiveKit:
- Go to SIP → Outbound Trunks
- Set the Address to your SignalWire SIP domain
- Add your SignalWire phone number(s) under Numbers
- Set Auth Username to your SignalWire phone number
- Set Auth Password to the Support-provided password
- Set Transport to
3(TLS) - Save the trunk
5. Initiate Calls
Use LiveKit's API to create a SIP Participant, which triggers an outbound call through the trunk.
Optional: Add Call Recording
To record outbound calls, create a second SWML script that calls record_call, then reference it via the confirm parameter in your main script:
yaml
# record.yaml
version: 1.0.0
sections:
main:
- record_call:
stereo: true
format: mp3
# main.yaml
version: 1.0.0
sections:
main:
- connect:
answer_on_bridge: true
from: "+1XXXXXXXXXX"
to: "%{call.to.replace(/^sip:/i, '').replace(/@.*/, '')}"
confirm: https://your-server.com/record.yamlTroubleshooting
- If calls fail to route, verify the SIP domain and auth credentials with SignalWire Support
- Check that
transport: 3is set in the LiveKit trunk — SignalWire requires TLS - The
toexpression in the SWML must correctly strip the SIP URI to an E.164 number
