I want to capture the changes in call status, like...
# ask-ai
c
I want to capture the changes in call status, like the call being ended by the user/by the agent using end_call/ crashed
t
Thanks for reaching out, Anton. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I’m here to help you understand how to capture changes in call status, like when a call ends—whether that’s by a user, an agent, or even due to a crash. You can do this by keeping an eye on the
sip.callStatus
participant attribute and using the
participant_attributes_changed
event in your application logic. Here’s a simple breakdown of the key steps: • Keep track of the
sip.callStatus
attribute, which shows states such as
dialing
,
ringing
,
active
, and
hangup
. • Use the
participant_attributes_changed
event to spot changes in call status and take action as needed. • Check out the
disconnect_reason
field in the SIP call info to understand why a call ended—whether it was a user action, a rejection, or a system error. If you’d like, I’d be happy to provide detailed examples or clarify any part of this for you. Just let me know! Sources: pkg/sip/participant.go | protobufs/livekit_sip.proto | SIP Integration | livekit/livekit_composite | DeepWiki | Video Conferencing Applications | livekit/livekit_composite | DeepWiki | livekit-protocol/livekit/protocol/sip.pyi
c
Where are those related relative to the ctx object in async def entrypoint(ctx: JobContext)?
t
I'd be happy to help you access and monitor
sip.callStatus
within the
ctx
object in your
async def entrypoint(ctx: JobContext)
function. You can use the
ctx.room
object to listen for participant events and check their attributes, which is a great way to keep track of changes. Here’s a simple way to get started: • Use
ctx.room.on("participant_attributes_changed", handler)
to listen for any updates in participant attributes, including
sip.callStatus
. • To focus on SIP participants, you can filter by checking if
participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP
or if
participant.identity
starts with
sip_
. • Then, access the
sip.callStatus
attribute by using
participant.attributes.get("sip.callStatus")
. If you’d like, I can provide a detailed code example to walk you through implementing this in your entrypoint function. Just let me know! Sources: SIP participant | LiveKit Docs | complex-agents/ivr-agent/agent.py | SIP Integration | livekit/livekit_composite | DeepWiki
c
How do I create a participant_attributes_changed listener? Point me to the exact page in docs, if possible
t
To help you set up a
participant_attributes_changed
listener, you can register an event listener on the
Room
object. Here’s a simple example in Python that might make things clearer:
Copy code
@room.on("participant_attributes_changed")
def on_participant_attributes_changed(changed_attributes: dict[str, str], participant: rtc.Participant):
    <http://logging.info|logging.info>("Participant attributes changed: %s %s", participant.attributes, changed_attributes)
If you'd like to dive deeper, the documentation is a great resource and you can check it out here. Please feel free to reach out if you have any more questions or need a hand with anything else—I’m here to help! Sources: Participant attributes and metadata | LiveKit Docs | livekit-rtc/livekit/rtc/room.py | Job lifecycle | LiveKit Docs | livekit/src/room/participant/remote_participant.rs | callback.go
c
What is @room ? Is it ctx.room?
t
Absolutely! When you're working within your
async def entrypoint(ctx: JobContext)
, the
@room
is actually referring to
ctx.room
. You can easily set up an event listener for attribute changes by using
ctx.room.on("participant_attributes_changed", handler)
. If you'd like, I’m here to help with more details or examples—just let me know!