How do I detect that user hang up the phone during...
# ask-ai
f
How do I detect that user hang up the phone during the call?
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.
I understand you'd like to detect when a user hangs up the phone during a call in LiveKit. A helpful way to do this is by keeping an eye on the
sip.callStatus
attribute of the SIP participant. This attribute clearly shows the current call state and will update to
hangup
when the user ends the call. Here’s a simple approach you can try: • Set up a listener for changes in the
sip.callStatus
attribute of the SIP participant. For instance, you can use an event listener to catch when the status switches to
hangup
. • Another option is to listen for the
participant_disconnected
room event, which triggers whenever any participant leaves the room. Just keep in mind that this event doesn’t specifically tell you if it was a hangup or another reason for disconnection. If you’d like, I’m here to help with more details or walk you through the implementation—just let me know! Sources: protobufs/livekit_sip.proto | telephony/sip_lifecycle.py | agent.py | Getting Help & Troubleshooting | livekit/livekit_composite | DeepWiki | Agent Testing & CI/CD | livekit/livekit_composite | DeepWiki
f
How do I move from participant_disconnected event to new SummaryAgent to summarize and log the history call?
t
To help you smoothly transition from the
participant_disconnected
event to a SummaryAgent that summarizes and logs the call history, here’s a simple step-by-step guide: 1. Listen for the
participant_disconnected
event:
Set up a handler in your room logic to catch this event whenever a participant leaves the room. 2. Filter for relevant participants: Make sure to check the participant type (like user vs agent) so that the summarization only triggers for the right people. 3. Access session history: You can grab the full conversation history by using the session’s history object, accessed via
session.history
. 4. Generate a summary: Use
session.generate_reply()
with clear instructions such as "Summarize the full conversation." 5. Log or store the summary: Go through
session.history.items
to log each message or save the summary for later use. If you’d like, I’m here to provide detailed code examples or help you with any part of the implementation—just let me know! Sources: Handling events | LiveKit Docs | terminal-client/client.py | livekit-rtc/livekit/rtc/room.py | agent-console/lib/event-types.ts | examples/avatar_agents/audio_wave/avatar_runner.py
f
Provide detailed code example
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!