what all fields can we extract from `ctx: JobCont...
# ask-ai
a
what all fields can we extract from
ctx: JobContext
in the entrypoint function, i know there is
ctx.room_name
but what more
t
Thanks for reaching out, siddhant. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Here are some fields and methods you can access from
ctx: JobContext
in the entrypoint function: •
ctx.connect()
- Method to connect to the room. •
ctx.room
- Access to the room object, which includes: ◦
ctx.room.name
- The name of the room. •
ctx.log_context_fields
- Fields to include in log entries. •
ctx.add_participant_entrypoint()
- Method to add participant entrypoint functions. •
ctx.proc.userdata
- Access to process userdata (for accessing data set in the prewarm function). These fields and methods allow you to interact with the LiveKit room, manage connections, handle participants, and access shared data within your agent application. Let me know if you need further clarification! Sources: Worker options | LiveKit Docs | Tree View: | dse-workbench
a
i have connected my livekit agent to telephony inbound-trunk, so now my agent will receive phone calls from customers. how do i now write the logic in my entrypoint function to extract the caller's phone number apart from just the
room name
which i can access through JobContext?
t
To extract the caller's phone number in your entrypoint function when your LiveKit agent is connected to a telephony inbound trunk, you can access it through the SIP participant attributes. Here's an example:
Copy code
# Add this import to the top of your file
from livekit import rtc

# In your entrypoint function, after connecting:
participant = await ctx.wait_for_participant()

# Check if the participant is a SIP participant
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
    # Extract the caller's phone number from SIP attributes
    caller_phone_number = participant.attributes['sip.phoneNumber']
    <http://logger.info|logger.info>(f"Caller phone number is {caller_phone_number}")
    # Add other logic here based on the caller's phone number
The
sip.phoneNumber
attribute contains the user's phone number for inbound calls, which is the phone number the call originates from. Please note that this attribute won't be available if
HidePhoneNumber
is set in the dispatch rule. Let me know if you need further assistance! Sources: SIP participant | LiveKit Docs