for an inbound sip call, we get a custom sip heade...
# ask-ai
o
for an inbound sip call, we get a custom sip header:
Copy code
X-TCN-Virtual-Number: 7788071156
i want to make it as
virtualNumber
but as
<tel:+17788071156|+17788071156>
that is adding a prefix of +1, if it doesn't exist. how?
t
Thanks for reaching out, Jaivarsan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're on the right track — here's the concise plan and exactly what to do. 1) Map the SIP header to an attribute • Add
headers_to_attributes
on your inbound trunk:
Copy code
{
  "trunk": {
    "name": "My Inbound Trunk",
    "numbers": [
      "+15105550100"
    ],
    "headers_to_attributes": {
      "X-TCN-Virtual-Number": "virtualNumber"
    }
  }
}
This exposes the header value as participant attribute
virtualNumber
. 2) Add the +1 prefix in your app where you read the attribute • LiveKit does not auto-format phone numbers, so format after retrieving
virtualNumber
. Example functions: Node.js:
Copy code
function formatVirtualNumber(v) {
  if (!v) return v;
  if (v.startsWith('+')) return v;
  if (v.length === 10) return '+1' + v;
  if (v.length === 11 && v.startsWith('1')) return '+' + v;
  return v;
}
Python:
Copy code
def format_virtual_number(v):
    if not v: return v
    if v.startswith('+'): return v
    if len(v) == 10: return '+1' + v
    if len(v) == 11 and v.startswith('1'): return '+' + v
    return v
Use the formatted value (e.g.,
+17788071156
) in your app logic after retrieving
participant.attributes['virtualNumber']
. Would you like a version that enforces E.164 validation or handles other country codes? Sources: SIP APIs | LiveKit docs | sip | livekit/livekit_composite | DeepWiki