After setting up a SIP dispatch rule, I no longer ...
# ask-ai
b
After setting up a SIP dispatch rule, I no longer seem to be able to connect a web client to my agent. What could I be doing wrong?
g
To troubleshoot the issue with connecting a web client to your agent after setting up a SIP dispatch rule, consider the following: 1. Dispatch Rule Configuration: Ensure that your dispatch rule is correctly configured. If you are using a
dispatchRuleIndividual
, it should route each caller into an individual room with the agent. Verify that the room names are correctly prefixed and that the rule is applied to the correct trunk ID. According to the LiveKit SIP Quickstart, the dispatch rule should look something like this:
Copy code
{
  "name": "My dispatch rule",
  "trunk_ids": [
    "<livekit_trunk_id>"
  ],
  "rule": {
    "dispatchRuleIndividual": {
      "roomPrefix": "call"
    }
  }
}
2. Room Name Consistency: Check that the room name used by the web client matches the room name generated by the dispatch rule. If the dispatch rule creates rooms with a specific prefix, ensure your web client is attempting to join the correct room. 3. Agent and Web Client Configuration: Ensure that both the agent and the web client are configured to connect to the same LiveKit server and that they are using the correct API keys and secrets. Verify that the agent is running and able to join rooms as expected. Would you like more detailed guidance on any of these steps? Sources: - LiveKit SIP Quickstart 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@millions-hair-24956 My Twilio/SIP connection to my agent is working. The agent is responding to phone calls. It is not responding to Web client voice chats. This used to work before I setup the SIP connection. I do have both SIP and Web using a "call" prefix for their rooms.
g
It seems likely that the issue with your web client voice chats not working after setting up the SIP connection could be related to room naming conflicts or configuration settings. Here are a few things to check: 1. Room Naming Conflicts: If both SIP and web clients are using the same "call" prefix for room names, there might be a conflict in how rooms are being created and joined. Ensure that the room names are unique for each session to avoid conflicts. You might consider appending a unique identifier or timestamp to the room names for web clients to differentiate them from SIP sessions. 2. Dispatch Rule and Room Management: Verify that the dispatch rule is not inadvertently affecting the web client connections. According to the LiveKit SIP Dispatch Rule documentation, dispatch rules can route calls into specific rooms, which might interfere with web client connections if not configured correctly. 3. Agent Configuration: Ensure that your agent is configured to handle both SIP and web client connections. Check that the agent is not restricted to only join rooms created by SIP calls. The agent should be able to join any room that matches the expected naming pattern. Would you like more detailed guidance on any of these steps? Sources: - LiveKit SIP Dispatch Rule documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@millions-hair-24956 I'm not seeing any problems related to your last suggestions. You have any other suggestions?
g
If the previous suggestions did not resolve the issue, consider the following additional steps: 1. Agent Logs and Debugging: Check the logs for your agent to see if there are any errors or warnings when a web client attempts to connect. This can provide insights into whether the agent is receiving the connection request and if there are any issues during the process. 2. Web Client Configuration: Ensure that the web client is correctly configured to connect to the LiveKit server. Verify that the API keys, server URL, and room names are correctly set in the web client configuration. Double-check that the web client is using the correct signaling server URL and that it can establish a WebSocket connection. 3. Network and Firewall Settings: According to the LiveKit Firewall Configuration, ensure that your network allows outbound traffic to the necessary LiveKit domains and ports. This includes allowing WebSocket connections over TCP port 443 and UDP traffic for media streams. 4. Room Lifecycle Management: Ensure that the room lifecycle is managed correctly. If rooms are not being closed properly after SIP calls, it might prevent new connections from web clients. Consider implementing a mechanism to clean up rooms after use. Would you like more detailed guidance on any of these steps? Sources: - LiveKit Firewall Configuration 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@millions-hair-24956 I'm suspecting that the room lifecylcle management may be the problem and that the SIP calls are not being closed. How can I make sure they close correctly?
g
To ensure that SIP calls and rooms are closed correctly, you can follow these steps: 1. Use the
deleteRoom
API
: According to the LiveKit Server APIs documentation, you can use the
deleteRoom
API to forcibly disconnect all participants and close the room. This can be done programmatically when you detect that a call should end.
Copy code
from livekit import RoomServiceClient

   client = RoomServiceClient("https://your.livekit.server", "api-key", "secret-key")
   client.delete_room("room-name")
2. Monitor Participant Events: Implement event listeners to monitor when participants leave the room. According to the LiveKit Managing Participants documentation, you can listen for participant leave events and trigger room closure if no participants remain. 3. Set Room Timeout: Configure a timeout for rooms to automatically close after a certain period of inactivity. This can be set when creating the room using the
empty_timeout
parameter, which specifies the number of seconds to keep the room open if no one joins. 4. Check SIP Participant Status: Ensure that SIP participants are correctly marked as disconnected when they leave. According to the LiveKit SIP Participant documentation, you can check the
sip.callStatus
attribute to verify the call status. Would you like more detailed guidance on any of these steps? Sources: - LiveKit Server APIs documentation - LiveKit Managing Participants documentation - LiveKit SIP Participant documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@millions-hair-24956 How can I have the SIP room created with the empty_timeout paramter?
g
To create a SIP room with the
empty_timeout
parameter, you need to explicitly create the room using the
CreateRoom
API before adding SIP participants. This allows you to set the
empty_timeout
parameter, which defines how long the room should remain open if no participants are present. Here's how you can do it: 1. Create the Room with
empty_timeout
: Use the
CreateRoom
API to create a room with the desired
empty_timeout
setting. This parameter specifies the number of seconds the room will remain open if no participants join.
Copy code
from livekit import RoomServiceClient

   client = RoomServiceClient("https://your.livekit.server", "api-key", "secret-key")
   room = client.create_room(
       name="sip-room",
       empty_timeout=300  # Set to 5 minutes (300 seconds)
   )
2. Add SIP Participants: Once the room is created, you can add SIP participants using the
CreateSIPParticipant
API. Ensure that the room name matches the one you created. 3. Monitor Room Status: Implement logic to monitor the room status and handle any necessary cleanup or notifications when the room is about to close due to the timeout. Would you like more detailed guidance on any of these steps? Sources: - LiveKit Server APIs documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@millions-hair-24956 I don't think this works as the room seems to be created before my agent is added to the conversation.
g
If the room is being created automatically before you have a chance to set parameters like
empty_timeout
, you can manage room creation explicitly by pre-creating the room before any participants join. Here's how you can handle this: 1. Pre-create the Room: Use the
CreateRoom
API to create the room with the desired settings before any participants, including SIP participants, join. This ensures that the room is configured with the
empty_timeout
and any other parameters you need.
Copy code
from livekit import RoomServiceClient

   client = RoomServiceClient("https://your.livekit.server", "api-key", "secret-key")
   room = client.create_room(
       name="sip-room",
       empty_timeout=300  # Set to 5 minutes (300 seconds)
   )
2. Dispatch the Agent: After the room is created, dispatch your agent to the room. According to the LiveKit Dispatching Agents documentation, you can use explicit dispatch to control when the agent joins the room. 3. Add SIP Participants: Once the room is ready and the agent is dispatched, you can proceed to add SIP participants. Ensure that the room name used for SIP participants matches the pre-created room. By pre-creating the room, you gain control over its configuration and ensure that all settings are applied before any participants join. Would you like more detailed guidance on any of these steps? Sources: - LiveKit Dispatching Agents documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@millions-hair-24956 It looks like the LiveKit console shows I still have a SIP session running out there even though there are no participants. Can I somehow kill it?
g
To terminate a SIP session that appears to be running without participants, you can use the
DeleteRoom
API to forcibly close the room and disconnect any lingering sessions. Here's how you can do it: 1. Use the
DeleteRoom
API
: This API will forcibly disconnect all participants and close the room. Even if there are no visible participants, this action ensures that any backend processes associated with the room are terminated.
Copy code
from livekit import RoomServiceClient

   client = RoomServiceClient("https://your.livekit.server", "api-key", "secret-key")
   client.delete_room("room-name")
2. Check for Room Closure: After calling the
DeleteRoom
API, verify in the LiveKit console that the room is no longer listed as active. This should remove any lingering SIP sessions. 3. Monitor for Future Sessions: Implement monitoring to ensure that rooms are closed properly after use. You can set up alerts or logs to notify you if a room remains open unexpectedly. If the room still appears active after these steps, it might be a display issue in the console. In such cases, you can contact LiveKit support for further assistance. Would you like more detailed guidance on any of these steps? Sources: - LiveKit Server APIs documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@millions-hair-24956 Trying to delete the room says it does not exist but the LiveKit UI shows I still have a session active. Can I delete the session?
g
It seems likely that the discrepancy between the LiveKit UI and the API response is due to a known issue where the dashboard may not update in real-time to reflect the actual state of rooms and sessions. Here are some steps you can take: 1. Verify with API: Use the
ListRooms
API to confirm the actual state of rooms. If the API indicates that the room does not exist, it is likely a display issue in the dashboard. According to the LiveKit Server APIs documentation, the
ListRooms
API should provide the current list of active rooms. 2. Check for Dashboard Updates: The LiveKit team has acknowledged that there can be delays in the dashboard updating to reflect the true state of rooms. This is a known issue, and they are working on improvements. If the API confirms the room is not active, it should not impact your billing or session limits. 3. Contact Support: If the issue persists and you need to ensure that no sessions are incorrectly billed or affecting your limits, consider reaching out to LiveKit support for assistance. They can provide more detailed insights and confirm the backend state. Would you like more detailed guidance on any of these steps? Sources: - LiveKit Server APIs documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@millions-hair-24956 I tried listing the rooms and it does not show any rooms available, but the LiveKit Sessions display still show 1 active room and the session started over 3 hours ago. Is there a way to restart the LiveKit project and clear all room and session info?
g
It seems likely that the discrepancy between the LiveKit API and the dashboard is due to a known issue with the dashboard not updating in real-time. To address this, you can try the following steps: 1. Restart the LiveKit Server: If you are self-hosting LiveKit, you can restart the LiveKit server to clear any cached session data. This can help ensure that the server state is reset. If you are using LiveKit Cloud, you may need to contact LiveKit support for assistance with restarting the project. 2. Clear Redis Cache: If you are using a distributed setup with Redis, clearing the Redis cache can help reset the session data. According to the LiveKit Distributed Setup documentation, Redis is used for room data and message bus, so clearing it can help resolve discrepancies. 3. Contact LiveKit Support: If the issue persists, consider reaching out to LiveKit support for assistance. They can provide more detailed insights and help ensure that the backend state is consistent with the dashboard. Would you like more detailed guidance on any of these steps? Sources: - LiveKit Distributed Setup documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.