Connecting UniFi Talk to a Twilio SIP Number (Inbound + Outbound)
How it works
Two-way calling between UniFi Talk and Twilio uses two separate call paths, configured in different places. Knowing this split is what makes setup (and troubleshooting) straightforward:
- Inbound (someone calls your Twilio number → your UniFi phone rings): handled by the phone number's voice webhook, which runs a small TwiML Bin that dials your registered SIP endpoint.
- Outbound (you dial out from your UniFi phone → a regular phone rings): handled by the SIP Domain's voice webhook, which runs a Function that places the call over the PSTN.
One rule ties it all together: use your phone number (plain digits) as the SIP username everywhere — in UniFi, in the credential list, and in the inbound dial target. Don't use a person's name. If the username and the dial target ever disagree, calls won't connect.
Prerequisites
A Twilio account with a voice-capable phone number, and a UniFi Talk setup (UDM/console) where you can add a third-party SIP provider.
Step 1 — Create the Twilio SIP Domain
In the Twilio Console: Voice → Manage → SIP Domains → Create SIP Domain.
Set the SIP URI to YOUR_SIP_DOMAIN. Note the active region (e.g. US1); your UniFi proxy will use the regional host YOUR_REGION_DOMAIN.
Step 2 — Create a Credential List
Voice → Manage → Credential lists → Create. Name the list YOUR_NUMBER (the phone number in plain digits). Add one credential with username YOUR_NUMBER and a strong password you'll reuse in UniFi. Attach this credential list to the SIP domain under the domain's Voice Authentication section.
Step 3 — Create the inbound TwiML Bin
Develop → TwiML Bins → Create. Name it something like "Inbound to UniFi." Paste:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial answerOnBridge="true"><Sip>sip:YOUR_NUMBER@YOUR_REGION_DOMAIN</Sip></Dial>
</Response>The SIP user here (YOUR_NUMBER) must exactly match the username your UniFi phone registers with. Save.
Step 4 — Point your phone number at the TwiML Bin
Phone Numbers → Manage → Active Numbers → your number. Under Voice, set "A call comes in" to the TwiML Bin from Step 3. Save. This completes the inbound path.
Step 5 — Create the outbound Function
Develop → Functions and Assets → create a Service and a Function (path /sip-router). This handler receives only outbound calls (every call arriving at the SIP domain originates from your phone), so it parses the dialed number out of the SIP URI, normalizes it to E.164, and dials it out:
exports.handler = function(context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
let dest = (event.To || "").replace("sip:", "").split("@")[0].split(";")[0].trim();
if (dest.indexOf("+") !== 0) {
if (/^\d{10}$/.test(dest)) { dest = "+1" + dest; }
else if (/^1\d{10}$/.test(dest)) { dest = "+" + dest; }
else if (/^\d{11}$/.test(dest)) { dest = "+" + dest; }
}
const dial = twiml.dial({ callerId: "+YOUR_NUMBER", timeout: 30 });
dial.number(dest);
callback(null, twiml);
};The 10-digit branch assumes a North American (+1) default; adjust for your country. Click Save, then Deploy All, and copy the deployed URL (YOUR_FUNCTION_URL).
Step 6 — Point the SIP Domain at the Function
Back on the SIP domain (Step 1), set the Voice configuration "A call comes in" to a Webhook (HTTP POST) at YOUR_FUNCTION_URL. Save. This completes the outbound path.
Step 7 — Configure the UniFi Talk SIP provider
In UniFi Talk: Settings → Phone Lines → 3rd party SIP → Create New (Custom). Set:
proxy:YOUR_REGION_DOMAINusername:YOUR_NUMBER← plain digits, matches the credential and the inbound dial targetpassword: the one from Step 2register:trueexpires:60force_rport:yesrtp_symmetric:yesrewrite_contact:yesqualify_frequency:30
Save and assign the line to a phone/user. A green status indicator means the phone is registered with Twilio.
Step 8 — (If your network filters by IP) allow Twilio's voice ranges
If you restrict SIP traffic at your firewall, allow Twilio's signaling/media ranges. Confirm the current list against Twilio's documentation; commonly included are: 54.172.60.0/30, 54.244.51.0/30, 168.86.128.0/18, 54.172.60.0/23, 54.244.51.0/24, 34.203.250.0/23.
Verify
Place one inbound call (any phone → your Twilio number) and one outbound call (UniFi phone → any phone). In Twilio, go to Monitor → Logs → Calls and confirm both appear as Completed with a real duration.
If a call fails, open that call's Request Inspector in the call details. It shows which webhook URL handled the call and the exact To / From / Direction values that arrived — the fastest way to see whether a call took the inbound (phone number) or outbound (SIP domain) path, and whether the SIP username matches end to end.