how to exit the call after a certain condition?
# ask-ai
a
how to exit the call after a certain condition?
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To exit or leave a call in LiveKit after a certain condition is met, you can do the following: • Define a function in your agent code that ends the call by removing the participant from the room. For example, you can create an
end_call
method and call it when your condition is met:
Copy code
@llm.ai_callable()
async def end_call(self):
    <http://logger.info|logger.info>(f"ending the call for {self.participant.identity}")
    await self.hangup()
Monitor call status through attributes like
sip.callStatus
. If it changes to
hangup
, you can exit the call programmatically. • Use LiveKit SDK methods to send a leave signal, such as
SendLeave()
or
SendLeaveWithReason()
in the Go SDK, to end a call directly. The approach depends on your environment and integration level, but generally, you implement a function to hang up and trigger it when your condition (such as user input or detection of voicemail) happens. If you want code examples or further clarification for a specific language or SDK, please let me know. Sources: Making calls using SIP | LiveKit Docs | lksdk package - github.com/livekit/server-sdk-go/v2 - Go Packages