How exactly the code should look like when you wan...
# ask-ai
l
How exactly the code should look like when you want to access the participant object of type sip in python?
t
Thanks for reaching out, Denis. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to access a SIP participant object in Python using LiveKit, you can check the participant's
kind
field to see if it’s a SIP participant. Here’s a little example to help you out:
Copy code
from livekit import rtc

async def on_participant_connected(participant: rtc.RemoteParticipant):
    # Let’s see if this participant is a SIP participant
    if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
        print(f"SIP Participant connected: {participant.identity}")
        
        # Grab those SIP-specific details
        sip_attributes = participant.attributes
        phone_number = sip_attributes.get("sip.phoneNumber", "Unknown")
        call_status = sip_attributes.get("sip.callStatus", "Unknown")
        trunk_id = sip_attributes.get("sip.trunkID", "Unknown")
        
        print(f"SIP Phone Number: {phone_number}")
        print(f"SIP Call Status: {call_status}")
        print(f"SIP Trunk ID: {trunk_id}")
    else:
        print(f"Standard participant connected: {participant.identity}")

# Hook up the event listener
room.on("participant_connected", on_participant_connected)
This little snippet listens for when someone connects, checks if they’re a SIP participant, and then pulls out some handy SIP info like their phone number, call status, and trunk ID. If you have any questions or want to dive deeper, just let me know—I’m here to help! Sources: Core API primitives | LiveKit Docs | README.md | complex-agents/ivr-agent/flask_livekit/extension.py | SIP participant | LiveKit Docs | SIP overview | LiveKit Docs