In calls we have two things one is dialed number w...
# ask-ai
s
In calls we have two things one is dialed number which are 7201234567 and caller number which re 4201234567 now how do I get dialed number in livekit from room
t
Thanks for reaching out, elish. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To get the dialed number in LiveKit from a room, it depends on whether the call is outbound or inbound: • Outbound Calls: The dialed number is available in the job metadata when creating a SIP participant. You can access it via
ctx.job.metadata
in your agent code. • Inbound Calls: The dialed number (caller number) is accessible from the SIP participant's attributes via
participant.attributes['sip.phoneNumber']
, but only if the
HidePhoneNumber
feature is not enabled in the dispatch rule. In summary: • Use
ctx.job.metadata
for the dialed number on outbound calls. • Use
participant.attributes['sip.phoneNumber']
for dialed/caller number on inbound calls (if phone number hiding is disabled). This will allow you to retrieve the dialed number or caller number accordingly from the LiveKit room. Sources: Agents telephony integration | LiveKit Docs | SipClient | LiveKit JS Server SDK - v2.9.7 | SIP participant | LiveKit Docs
s
In this code how do I get it?
Copy code
async def entrypoint(ctx: JobContext):
    await ctx.connect()
    room = ctx.room
I am talking about inbound call if possible can you show me how do I get dialed number as well as reciver number both?
t
Hey there! Let me walk you through how to grab the dialed and receiver numbers during an inbound call in LiveKit. It's actually pretty straightforward once you know the trick. Here's a handy code snippet you can use in your
entrypoint
function:
Copy code
async def entrypoint(ctx: JobContext):
    await ctx.connect()
    room = ctx.room

    # Get the first SIP participant in the room
    participant = [p for p in room.remote_participants.values() if p.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP][0]

    # Get the dialed number (caller number) from participant attributes
    dialed_number = participant.attributes.get('sip.phoneNumber')

    # Get the receiver number (the number that was dialed) from participant attributes
    receiver_number = participant.attributes.get('sip.trunkPhoneNumber')

    print(f"Dialed Number: {dialed_number}")
    print(f"Receiver Number: {receiver_number}")
Just a quick pro tip: make sure you've got the
HidePhoneNumber
feature disabled in your dispatch rule so you can access these values. Easy peasy! Sources: SIP participant | LiveKit Docs