how to gracefully delete room in case when user sa...
# ask-ai
l
how to gracefully delete room in case when user says something and immediately hangs up
t
Thanks for reaching out, Deepak. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To gently and smoothly delete a room when a user hangs up right after saying something, here’s a simple approach you can follow: 1. Detect User Intent: Pay attention to when the user indicates they want to end the call, whether that’s through their words or by hanging up. 2. Ensure Audio Completion: Use
ctx.wait_for_playout()
to make sure the agent’s audio finishes playing completely before moving forward. 3. Delete the Room: Then, call the
delete_room
API to close the session for everyone involved and tidy up any resources. Here’s an example:
Copy code
from livekit import api

async def hangup_call():
    ctx = get_job_context()
    if ctx is None:
        return
    await ctx.api.room.delete_room(
        api.DeleteRoomRequest(room=ctx.room.name)
    )
This way, you won’t have any leftover recordings or resources hanging around. If you’d like, I’m here to help you with any part of this process—just let me know! Sources: Making calls using SIP | LiveKit Docs | agent.py | Agents telephony integration | LiveKit Docs | Job lifecycle | LiveKit Docs | telephony/sip_lifecycle.py
l
there is a case when user says something and quickly hangs up. In this case, room gets deleted even before the user last transcript becomes part of the chat context
t
I'd love to understand a bit more about how the user transcript is being processed and stored in your setup so I can assist you better. For instance: • Are you utilizing LiveKit's recording or transcription features? • Is there any delay in processing the transcript before it gets included in the chat context? • Do you find it necessary to delay deleting the room until the transcript is fully saved? Knowing these details will really help me offer the most helpful and precise solution for you.
l
• Do you find it necessary to delay deleting the room until the transcript is fully saved? YES
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!
l
how to make sure that the last user transcript is saved before room is deletd