Can i get sip.trunkPhoneNumber and sip.phoneNumber...
# ask-ai
f
Can i get sip.trunkPhoneNumber and sip.phoneNumber from JobContext without need to wait_for_participant?
t
Thanks for reaching out, Taras. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can retrieve
sip.trunkPhoneNumber
and
sip.phoneNumber
from
JobContext
without needing to use
wait_for_participant
. These attributes are conveniently added to SIP participants by LiveKit and become accessible through the
JobContext.room
object once the SIP participant has joined. You’ll find them inside the participant's
attributes
dictionary, which is set up when the SIP participant is created. Here are a couple of friendly ways to get these attributes: • From New Participant Events: You can listen to the
participant_connected
event and grab the attributes right when a SIP participant joins. • From Existing Participants: Or, you can loop through
job_context.room.remote_participants
to access the attributes of participants who are already in the room when you start. If you'd like, I’m here to help with more details or examples on how to implement this—just let me know! Sources: SIP participant | LiveKit Docs | rpc/sip_test.go | telephony/warm_handoff.py
f
provide examples
t
I'm happy to share some examples to help you retrieve
sip.trunkPhoneNumber
and `sip.phoneNumber`: 1. From New Participant Events:
Copy code
def on_participant_connected_handler(participant):
    if participant.kind == "PARTICIPANT_KIND_SIP":
        trunk_phone = participant.attributes.get("sip.trunkPhoneNumber")
        user_phone = participant.attributes.get("sip.phoneNumber")

        print(f"Trunk Phone Number: {trunk_phone}")
        print(f"User Phone Number: {user_phone}")
Here, you listen to the
participant_connected
event and grab the attributes right when a SIP participant joins. It’s a great way to catch those details in real time. 2. From Existing Participants:
Copy code
for participant in ctx.room.remote_participants.values():
    if participant.kind == "PARTICIPANT_KIND_SIP":
        trunk_phone = participant.attributes.get("sip.trunkPhoneNumber")
        phone = participant.attributes.get("sip.phoneNumber")
        print(f"SIP Participant: {trunk_phone} → {phone}")
This example goes through
job_context.room.remote_participants
to find the attributes of participants who are already in the room when you start up. It’s handy for picking up existing info. If you have any questions or want me to walk you through more examples, just let me know—I’m here to help!