How do you get the number the caller called from?
# ask-ai
r
How do you get the number the caller called from?
✅ 1
t
Thanks for reaching out, Rithvik. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking how to get the phone number the caller dialed (DNIS). You can read that from the SIP participant metadata: the called number is stored in
data.from
. Examples: 1. Participant-connected handler (Python)
Copy code
@room.on("participant_connected")
async def on_participant_connected(participant):
    called_number = participant.metadata.get("data.from")
    print(f"Caller dialed: {called_number}")
1. From job/agent context (find SIP participant)
Copy code
sip_participant = next(
    (p for p in ctx.room.remote_participants.values() if p.kind == ParticipantKind.PARTICIPANT_KIND_SIP),
    None
)
if sip_participant:
    called_number = sip_participant.metadata.get("data.from")
    print(f"Call was received on number: {called_number}")
If you want, tell me which language or part of your agent (entrypoint, tool, or event handler) you're using and I’ll give a targeted snippet. Sources: Agents telephony integration | LiveKit Documentation | sip | livekit/livekit_composite | DeepWiki | How to do call transfers with Five9 | LiveKit, with interactive elements
r
metadata is string type
t
Good point — thanks for calling that out. You're right:
participant.metadata
is a string. Two ways to get the called number (DNIS): • If the metadata string contains JSON with
data.from
, parse it first. Example (Python):
Copy code
import json

meta = participant.metadata  # string
data = json.loads(meta)
called_number = data.get("data", {}).get("from")
• Prefer using participant attributes when available: SIP headers (DNIS) are often mapped to participant attributes via
headers_to_attributes
. Example:
Copy code
called_number = participant.attributes.get("five9.call_dnis")  # or whatever attribute key your trunk maps to
Which integration are you using (SIP trunk provider or LiveKit Phone Numbers)? I can give a tailored snippet for your case. Sources: Agent Builder | LiveKit Documentation | Server-side | livekit/livekit_composite | DeepWiki | How to do call transfers with Five9 | LiveKit | livekit-protocol/livekit/protocol/sip.pyi | livekit/attrs.go, with interactive elements
r
metadata is returning empty
t
Thanks — I’m sorry that
metadata
is coming back empty. To help quickly, I need a few details about your setup: • Are you using a SIP trunk provider or LiveKit Phone Numbers? • Where and when are you reading
participant.metadata
(event handler, agent entrypoint, or after join)? • Do you have a
headers_to_attributes
mapping configured on your trunk (or any SIP header mappings)? • Can you share a short snippet of how you’re accessing the participant (no secrets)? With those, I’ll tell you the exact place to read DNIS (attributes vs parsed metadata) and a targeted code snippet to extract it. , with interactive elements