faint-arm-51818
09/03/2025, 3:00 PMtall-airline-16756
09/03/2025, 3:00 PMtall-airline-16756
09/03/2025, 3:02 PMsip.callStatus of the participants. When it switches to hangup, that’s your cue to send the SMS.
• AI Agent end_call Function: If you’re working with AI agents, you can set up a custom end_call function to send an SMS once the AI decides the conversation is wrapped up.
Would you like me to walk you through the steps or share some code examples for any of these? Just let me know!
Sources: livekit-protocol/livekit/protocol/sip.pyi | pkg/sip/inbound.go | SIP participant | LiveKit Docs | Making calls using SIP | LiveKit Docs | Community & Support | livekit/livekit_composite | DeepWikifaint-arm-51818
09/03/2025, 3:04 PMtall-airline-16756
09/03/2025, 3:04 PM@llm.ai_callable()
def end_call(self):
"""Called when the user wants to end the call"""
logger.info("User requested to end the call")
# End the call by removing the participant
await self.hangup()
# Send an SMS after the call ends
await self.send_sms(
phone="+1234567890", # Just swap this out with the recipient's phone number
message="Thank you for your call. If you have further questions, feel free to reach out!"
)
Here are the steps to get this going:
1. Make sure your AI agent knows when the user wants to end the call.
2. Swap the phone parameter with the right phone number, which you can grab from participant info or your database.
3. Set up the send_sms method to work with an SMS service like Twilio or AWS SNS.
If you want, I can also share an example of the send_sms method for Twilio integration—just let me know!faint-arm-51818
09/03/2025, 3:11 PMtall-airline-16756
09/03/2025, 3:12 PMroom.on or session.on callbacks in LiveKit. Here are some key events that might help you out:
• `room.on("participant_disconnected")`: This one fires when a participant leaves the room. It’s great for spotting when everyone’s gone and cleaning things up.
• `session.on("close")`: This triggers when an agent’s session ends, which usually means the call is over. Perfect for tidying up, like deleting the room.
Here’s a quick example for `room.on("participant_disconnected")`:
def _on_participant_disconnected(_: rtc.Participant):
if len(ctx.room.remote_participants) == 0:
print("All participants have left the room.")
ctx.room.on("participant_disconnected", _on_participant_disconnected)
And here’s how you might use `session.on("close")`:
@session.on("close")
def on_close(ev):
print(f"Session closed, reason: {ev.reason}")
ctx.delete_room() # Optionally delete the room
If you want, I’m here to help you set these up or answer any questions you have!
Sources: livekit-rtc/livekit/rtc/room.py | examples/voice_agents/realtime_joke_teller.py | Agents telephony integration | LiveKit Docs | complex-agents/ivr-agent/ivr-agent-frontend/src/App.tsxfaint-arm-51818
09/03/2025, 3:14 PMtall-airline-16756
09/03/2025, 3:14 PMincoming, that means the user didn’t join the call.
◦ If it switches to active, then the user joined and there was a conversation.
• Look at Participant Events:
◦ The PARTICIPANT_JOINED event tells you the user entered the room.
◦ The PARTICIPANT_ACTIVE event shows the user actually engaged in the call.
◦ If the user leaves before hitting the ACTIVE state, it’s likely no meaningful conversation took place.
Need any more details or some examples on how to set this up? Just let me know—I’m happy to help!
Sources: Voice Assistants | livekit/livekit_composite | DeepWiki | Voice Assistants | livekit/livekit_composite | DeepWiki | livekit/livekit_sip.pb.go | livekit-protocol/src/livekit.rs | Making outbound calls | LiveKit Docsfaint-arm-51818
09/03/2025, 3:15 PMtall-airline-16756
09/03/2025, 3:16 PMTrackMuted, IsSpeakingChanged, or ConnectionQualityChanged. Here’s a simple JavaScript example:
participant.on(ParticipantEvent.TrackMuted, (publication) => {
console.log('Track muted:', publication.trackSid);
});
• Room-Level Events: Another way is to use the Room object to watch all participants at once. Here’s how you might do it in Python:
@room.on("track_published")
def on_track_published(publication, participant):
print(f"Track published by {participant.identity}")
• Server-Side Monitoring: And if you’re working on the backend, webhooks are great for getting events like participant_joined and participant_left.
If you’d like, I can share more details or examples for any of these methods—just let me know!
Sources: Handling events | LiveKit Docs | examples/demo/demo.ts | src/useParticipant.ts | examples/basic_room.py | lib/src/context/participant_context.dartfaint-arm-51818
09/03/2025, 3:30 PMtall-airline-16756
09/03/2025, 3:30 PMactive, it means the user joined and had a chat. You can then go ahead and trigger the SMS once the call wraps up.
1. Use Participant Events:
◦ Watch for the PARTICIPANT_ACTIVE event to make sure the user actually took part in the call. If you see this, you can send the SMS after the PARTICIPANT_LEFT event.
1. OnSessionEnd Callback:
◦ For SIP calls, try using the OnSessionEnd handler to peek at call details like ended_at and disconnect_reason. Pair this with sip.callStatus to double-check a conversation happened before sending your SMS.
If you'd like, I can walk you through how to set up any of these methods—just let me know!faint-arm-51818
09/03/2025, 3:34 PMtall-airline-16756
09/03/2025, 3:35 PMsip.callStatus attribute doesn’t stay active for the entire session. It actually updates to show the current state of the SIP call as things happen. For example:
• When the call connects, the status switches to active.
• Once the call ends, it changes to hangup.
So, by keeping an eye on sip.callStatus, you’ll know right when the call moves to hangup, meaning the session is over.
Sources: SIP participant | LiveKit Docs | telephony/sip_lifecycle.py