What is the right way to get the caller ID informa...
# ask-ai
n
What is the right way to get the caller ID information when handling a job? I want to get some metadata from the dispatch rule and things like the caller phone number and what number they dialed from the SIP data.
t
Thanks for reaching out, Stephen. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you retrieve caller ID information, dispatch rule metadata, and SIP data in LiveKit! Here are some ways you can do this: • Caller ID Information: You can access SIP-specific participant attributes like
sip.phoneNumber
during a live room session. For instance, if you're using the Node.js SDK, you can check participants through the Room API to find details such as the caller's phone number. • Dispatch Rule Metadata: The
ListSIPDispatchRule
API is a great tool to retrieve metadata defined in your dispatch rules. This metadata will be part of the participant attributes when the rule creates SIP participants. • SIP Data: You can set up SIP header mappings using
headers_to_attributes
or
SIPHeaderOptions
to include SIP headers as attributes. Also, attributes like
sip.callStatus
and
sip.trunkID
can provide detailed call-level information. If you'd like, I can share specific examples or guide you step-by-step through implementing these methods. Just let me know how I can assist you further! Sources: SIP participant | LiveKit Docs | SIP APIs | LiveKit Docs | protobufs/rpc/io.proto | Docs::Telephony
n
Can you give me some code examples in python?
t
I'm happy to share some Python code examples that can help you retrieve caller ID information, dispatch rule metadata, and SIP data. Let’s walk through them together: • Retrieve Caller ID Information:
Copy code
from livekit import api

lkapi = api.LiveKitAPI()

# List participants in a room
participants = await lkapi.room.list_participants("your-room-name")

for participant in participants:
    # Access caller phone number from SIP attributes
    phone_number = participant.attributes.get("sip.phoneNumber")
    print("Caller Phone Number:", phone_number)
• Retrieve Dispatch Rule Metadata:
Copy code
from livekit import api

lkapi = api.LiveKitAPI()

# List SIP dispatch rules
dispatch_rules = await lkapi.sip.list_dispatch_rule()

for rule in dispatch_rules:
    print("Dispatch Rule ID:", rule.sip_dispatch_rule_id)
    print("Metadata:", rule.metadata)
• Retrieve SIP Data:
Copy code
from livekit import api

lkapi = api.LiveKitAPI()

# List participants in a room
participants = await lkapi.room.list_participants("your-room-name")

for participant in participants:
    # Access SIP attributes like call status and trunk ID
    call_status = participant.attributes.get("sip.callStatus")
    trunk_id = participant.attributes.get("sip.trunkID")
    print("Call Status:", call_status)
    print("Trunk ID:", trunk_id)
If you have any questions or need a bit more detail on any part, please don’t hesitate to ask. I’m here to help!