I got a number from twilio, setup the sip trunk, m...
# ask-ai
a
I got a number from twilio, setup the sip trunk, my freeswitch server receives the call and tries to bridge to livekit. but livekit returns 503. Here is the summary of the problem ## Problem Phone number +19793169351 configured in LiveKit SIP trunk returns "503 Service Unavailable" when called. Other phone numbers on the same FreeSWITCH server, using the same LiveKit trunk and dispatch rule, work correctly. ## Observable Facts ### The Failing Number - Number: +19793169351 - Provider: Twilio Elastic SIP Trunk - Caller origin: +15106049930 - Response: 503 Service Unavailable from LiveKit (within 1ms) ### Working Numbers (Examples) - Number: +902162351219 (Provider: Verimor) - Number: +902162125830 (Provider: Wespoke) - Same response flow: 100 → 180 → 183 → 200 OK → Call connects ### Infrastructure (Same for All) - FreeSWITCH server: 91.98.71.57 - LiveKit trunk: ST_CxLmHYdYMLRy - LiveKit dispatch rule: SDR_xZ8LxKK2tDtd - LiveKit endpoint: 567c09dlu6y.eu.sip.livekit.cloud:5060 (UDP) - Agent infrastructure: Running and working ## SIP Message Details ### INVITE FreeSWITCH Sends to LiveKit (Failing Number) INVITE sip:19793169351@567c09dlu6y.eu.sip.livekit.cloud:5060 SIP/2.0 From: "UJDDGMFMON" sip:freeswitch_uz@567c09dlu6y.eu.sip.livekit.cloud To: sip:19793169351@567c09dlu6y.eu.sip.livekit.cloud:5060 X-DID: 19793169351 X-From: +15106049930 X-Called-Number: 19793169351 X-Caller-Number: +15106049930 X-Call-ID: 37e84faa-ad2c-4786-aabc-5e395d12f5e2 X-FreeSWITCH-Server: http://91.98.71.57:8888 X-FreeSWITCH-UUID: 37e84faa-ad2c-4786-aabc-5e395d12f5e2 ### LiveKit Response (Failing Number) SIP/2.0 503 Service Unavailable Reason: Q.850;cause=16;text="NORMAL_CLEARING" ## Backend Processing (Successful) Backend successfully processes the call: ```json { "fromNumber": "+19793169351", "toNumber": "+15106049930", "assistantId": "cmhrxqjkl000rpj0zzfvrn54q", "internalCallId": "e007ab49-4202-4272-b391-7cc48dac150b", "freeswitchUuid": "37e84faa-ad2c-4786-aabc-5e395d12f5e2", "roomName": "call-6928ea10-98a2-45f5-8903-e21beaea7355" } - Assistant found: ✅ - Call record created: ✅ - UUID mapping stored: ✅ - call-workaround.sh: HTTP 200 ✅ LiveKit Configuration SIP Trunk Numbers Array "numbers": [ "+19793169351", "19793169351", "9793169351", "+902162351219", "902162351219", "2162351219", "+902162125830", "902162125830", "2162125830" ] SIP Trunk Settings { "allowedAddresses": ["93.174.164.26", "91.98.71.57", "10.1.99.0"], "authUsername": "freeswitch_uz", "authPassword": "LiveKit2024SecurePass!", "headersToAttributes": { "X-DID": "did", "X-From": "from_number", "X-Called-Number": "did", "X-Caller-Number": "from_number" } } Dispatch Rule { "rule": { "dispatchRuleIndividual": { "roomPrefix": "call" } }, "trunkIds": ["ST_CxLmHYdYMLRy"], "metadata": "{\"dispatch\":\"agent\",\"trunk\": \"freeswitch-93.174.164.26\", \"assistant_id\": \"${assistant_id}\", \"phone_number\": \"${from_number}\", \"call_id\": \"${call_id}\", \"did\": \"${did}\"}", "roomConfig": { "agents": [ { "metadata": "{\"assistant_id\": \"${assistant_id}\", \"phone_number\": \"${from_number}\", \"call_id\": \"${call_id}\", \"did\": \"${did}\"}" } ] } } FreeSWITCH Configuration Failing Number Dialplan <condition field="destination_number" expression="^(gw\+UJDDGMFMON|Wespok e1|\+19793169351|19793169351|9793169351)$"> <action application="set" data="sip_h_X-DID=19793169351"/> <action application="set" data="full_did=+19793169351"/> <action application="system" data="/usr/local/freeswitch/scripts/call-workaround.sh '${full_did}' '${uuid}' '${caller_id_number}' '$${freeswitch_server_url}' '$${sip_media_shared_token}'"/> <action application="bridge" data="{sip_h_X-DID=19793169351,...}sofia/g ateway/livekit_udp/19793169351"/> </condition> Working Number Dialplan (Example) <condition field="destination_number" expression="^(gw\+VERIMOR|gw\+902162351219|902162351219|2162351219)$"> <action application="set" data="sip_h_X-DID=902162351219"/> <action application="set" data="full_did=+902162351219"/> <action application="system" data="/usr/local/freeswitch/scripts/call-workaround.sh '${full_did}' '${uuid}' '${caller_id_number}' '$${freeswitch_server_url}' '$${sip_media_shared_token}'"/> <action application="bridge" data="{sip_h_X-DID=902162351219,...}sofia/ gateway/livekit_udp/2162351219"/> </condition> What We've Verified - ✅ Number is in trunk's numbers array (3 formats) - ✅ Source IP (91.98.71.57) is in allowedAddresses - ✅ Authentication succeeds (no 401/407) - ✅ Trunk ID matches dispatch rule trunkIds - ✅ Backend assigns assistant successfully - ✅ FreeSWITCH sends INVITE to LiveKit - ❌ LiveKit immediately returns 503 Question What causes LiveKit to immediately return 503 Service Unavailable for this specific phone number configuration while accepting other numbers on the same trunk with the same dispatch rule?
t
Thanks for reaching out, Taha. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm sorry you're experiencing the 503 Service Unavailable error with this phone number. This issue often happens because of restrictions in the LiveKit SIP trunk configuration. Specifically, it might be that the phone number isn’t listed in the
allowedNumbers
array of the trunk configuration. When this array is set, only the numbers included there are accepted. To help you get this sorted, here are a few things you can check: • Make sure the phone number causing trouble is added to the
allowedNumbers
array in your trunk configuration. • Double-check that the
authUsername
,
authPassword
, and
allowedAddresses
are all set correctly, as these need to match the caller number restrictions. • Take a look at the dispatch rule to confirm it corresponds with the trunk ID and includes the right metadata for the number. Also, it can be really helpful to review both your SIP provider's logs and LiveKit's call logs to see exactly where the call is running into trouble. If you’d like, I’m here to guide you through these steps or answer any questions. Just let me know! Sources: SIP inbound trunk | LiveKit docs | SIP APIs | LiveKit docs | livekit/livekit_sip.pb.go | Create and configure a Plivo SIP trunk | LiveKit docs
a
don't you see the allowed numbers in my message?
t
Thank you for pointing out that the phone number
+19793169351
is indeed listed in the
numbers
array of the trunk configuration. Since this part is already set up, the issue might be coming from somewhere else. Let’s explore a few other areas together: • Double-check that the dispatch rule metadata and room configuration are properly set to handle this specific number. • Make sure the FreeSWITCH server is sending the right headers and attributes (like
X-DID
,
X-Caller-Number
) for this number. • Look into any restrictions or overrides in the LiveKit backend that might be affecting this particular number. If you’ve already gone through these steps, just let me know! I’m here to help you dig deeper and get this sorted out.
a
you can see my dispatch rule in my message
t
Thank you so much for bringing this to my attention. Since the dispatch rule and trunk configuration seem to be set up correctly, it’s possible that the issue might be related to how LiveKit is handling this particular number internally. To help move things forward, I suggest we take a look at the following: • Double-check that the
X-DID
header value matches the format LiveKit expects to process the call smoothly. • Take a peek at LiveKit's call logs for this number to see if there are any unusual entries or errors during processing. • Make sure there aren’t any backend restrictions or overrides tied to this number that might be causing the 503 response. If these steps don’t uncover the root of the problem, we might need to dig a bit deeper. Please feel free to reach out if you’d like any help accessing or understanding the call logs—I’m here to support you!
a
also there is a working number example and there is a non working example
t
Thank you so much for sharing both the working and non-working examples. Since the configurations for both numbers look quite similar, the issue might be due to some subtle differences in how LiveKit interprets the incoming SIP headers or handles that particular number. To help us get to the bottom of this, here are a few focused checks you can try: • Take a look at the SIP INVITE headers for both the working and non-working numbers to see if there are any small differences in the
X-DID
,
X-Caller-Number
, or other custom headers. • Double-check that the
destination_number
in the FreeSWITCH dialplan for the number that's having trouble matches the expected format and is correctly passed to LiveKit. • See if there are any specific backend rules or restrictions within LiveKit that might be affecting this number differently. If these steps don’t uncover the issue, it might be helpful to dig a bit deeper into LiveKit’s backend processing for this particular number. Please feel free to reach out if you’d like a hand with any of these checks—I’m here to help!
a
@refined-appointment-81829 any idea what is the problem here? I am so stuck
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!