<@U084APK40NS>, I have a problem with receiving in...
# ask-ai
f
@millions-hair-24956, I have a problem with receiving incoming calls via Twilio SIP. I have set up the inbound trunk and dispatch rules as per documentation, but phone keeps ringing and agent is not attached to room. I think my dispatch rule is working because it's showing the prefix "call-" in the session logs, but still not connecting to the agent. I made changes in my agent to publish the audio track upon joining the room. I have correct trunk id defined in dispatch rules. How should I debug this issue?
g
To debug the issue of incoming calls not connecting to the agent, ensure the following: 1. Audio Track Publication: Verify that the agent is indeed publishing an audio track upon joining the room. The call will keep ringing until an audio track is published by at least one participant in the room. This is a common issue when the agent does not publish an audio track, as mentioned in LiveKit Slack. 2. Network and Firewall Settings: Check if your local network allows RTP traffic on the necessary ports (UDP 10000-20000). Ensure there are no firewall settings blocking this traffic, as suggested in LiveKit Slack. 3. Twilio and LiveKit Logs: Review the Twilio call logs for any error messages or warnings related to the call. Also, enable detailed logging in your Python agent to capture any logs generated during the call attempt, especially around audio track publication. Would you like more detailed steps on any of these points? Sources: - LiveKit Slack - LiveKit Slack 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
f
@millions-hair-24956 Please provide me the details steps on the sip configuration at twilio and livekit again. The provided documentation in LiveKit portal doesn't seem to be giving the correct picture. Also I would like more detailed steps on point 1. Audio track publication.
@millions-hair-24956, I don't have permissions or I can't open the the slack links you shared in the above message.
g
To configure SIP with Twilio and LiveKit, follow these steps: 1. Twilio SIP Trunk Setup: - Purchase a Phone Number: Ensure you have a phone number purchased from Twilio. - Create a SIP Trunk: In Twilio, create a SIP trunk and configure it to send SIP traffic to your LiveKit SIP instance. The domain name for your SIP trunk should end in
pstn.twilio.com
. - Configure Origination URI: Set the origination URI to point to your LiveKit SIP server. For example,
sip:<your-project-id>.sip.livekit.cloud;transport=tcp
. 2. LiveKit SIP Configuration: - Set Up Environment Variables: Configure the LiveKit CLI with your server URL, API key, and secret.
Copy code
export LIVEKIT_URL=<your LiveKit server URL>
     export LIVEKIT_API_KEY=<your API Key>
     export LIVEKIT_API_SECRET=<your API Secret>
- Create Inbound Trunk: Use the LiveKit CLI to create an inbound trunk. Create a JSON file (
inbound-trunk.json
) with your phone number and authentication details.
Copy code
{
  "trunk": {
    "name": "Twilio inbound trunk",
    "numbers": [
      "+15105550100"
    ],
    "auth_username": "<username>",
    "auth_password": "<password>"
  }
}
Run the command:
lk sip inbound create inbound-trunk.json
. - Create Dispatch Rule: Create a dispatch rule to route calls to a LiveKit room. Create a JSON file (
dispatch-rule.json
) with the trunk ID and room prefix.
Copy code
{
  "name": "My dispatch rule",
  "trunk_ids": [
    "<livekit_trunk_id>"
  ],
  "rule": {
    "dispatchRuleIndividual": {
      "roomPrefix": "call"
    }
  }
}
Run the command:
lk sip dispatch create dispatch-rule.json
. 3. Audio Track Publication: - Ensure your agent publishes an audio track as soon as it joins the room. This can be a silent track for testing purposes. - Use the LiveKit SDK to publish an audio track. Here's a basic example in Python:
Copy code
from livekit import rtc

     async def publish_audio_track(room):
         # Create a local audio track
         audio_track = rtc.LocalAudioTrack.create()
         # Publish the audio track to the room
         await room.local_participant.publish_track(audio_track)

     # Connect to the room and publish the track
     room = await rtc.connect("wss://<your-livekit-url>", token="<your-token>")
     await publish_audio_track(room)
Would you like more information on any specific step? Sources: - LiveKit SIP Quickstart - LiveKit SIP Overview 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
f
@millions-hair-24956, in the step Create Inbound Trunk, do the auth_username need to be created anywhere i mean in Twilio or some where before adding it to the inbound_trunk.json file?
g
It seems likely that the
auth_username
and
auth_password
used in the
inbound-trunk.json
file are meant for authenticating the SIP trunk with your SIP provider, such as Twilio. These credentials should be configured in your SIP provider's settings to ensure that the LiveKit server can authenticate incoming calls. 1. Twilio Configuration: In Twilio, you typically set up authentication credentials when configuring your SIP trunk. This involves creating a credential list with a username and password that you will use in your LiveKit configuration. 2. LiveKit Configuration: Use the same
auth_username
and
auth_password
in your
inbound-trunk.json
file to ensure that LiveKit can authenticate incoming calls from Twilio. If you haven't set up these credentials in Twilio, you should do so in the Twilio console under the SIP trunk settings. Would you like more detailed guidance on setting up these credentials in Twilio? Sources: - LiveKit SIP Quickstart 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
f
@millions-hair-24956, auth credentials are given while setting up Outbound calls in Twilio. I do not have outbound scenario yet. Do I still need to setup this the auth credentials?
g
For inbound calls, setting up authentication credentials (
auth_username
and
auth_password
) is not strictly necessary unless your SIP provider requires it for security purposes. However, it is a good practice to use authentication to prevent unauthorized access to your SIP trunk. 1. Inbound Trunk Authentication: If your SIP provider, such as Twilio, supports or requires authentication for inbound calls, you should configure these credentials in both your SIP provider's settings and in the
inbound-trunk.json
file used by LiveKit. This ensures that only authenticated requests are accepted by your LiveKit instance. 2. Twilio Configuration: While Twilio typically requires authentication for outbound calls, you can also set up authentication for inbound calls if desired. This involves creating a credential list in Twilio and using those credentials in your LiveKit configuration. If your current setup does not require authentication for inbound calls, you can proceed without it. However, if you encounter issues or want to enhance security, consider setting up these credentials. Would you like more information on configuring authentication for inbound calls? Sources: - LiveKit SIP Quickstart 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
f
@millions-hair-24956, atleast for the testing now I am setting up the credentials. I want test a simple scenario where call to a Twilio number going through SIP and conversing with livekit agent.
g
To test a simple scenario where a call to a Twilio number goes through SIP and converses with a LiveKit agent, follow these steps: 1. Twilio Setup: - Purchase a Phone Number: Ensure you have a Twilio phone number. - Create a SIP Trunk: In Twilio, create a SIP trunk and configure it to send SIP traffic to your LiveKit SIP instance. Set the origination URI to
sip:<your-project-id>.sip.livekit.cloud;transport=tcp
. - Configure Authentication: If you choose to use authentication, create a credential list in Twilio with a username and password. 2. LiveKit Setup: - Set Up Environment Variables: Configure the LiveKit CLI with your server URL, API key, and secret.
Copy code
export LIVEKIT_URL=<your LiveKit server URL>
     export LIVEKIT_API_KEY=<your API Key>
     export LIVEKIT_API_SECRET=<your API Secret>
- Create Inbound Trunk: Use the LiveKit CLI to create an inbound trunk. Create a JSON file (
inbound-trunk.json
) with your phone number and authentication details.
Copy code
{
  "trunk": {
    "name": "Twilio inbound trunk",
    "numbers": [
      "+15105550100"
    ],
    "auth_username": "<username>",
    "auth_password": "<password>"
  }
}
Run the command:
lk sip inbound create inbound-trunk.json
. - Create Dispatch Rule: Create a dispatch rule to route calls to a LiveKit room. Create a JSON file (
dispatch-rule.json
) with the trunk ID and room prefix.
Copy code
{
  "name": "My dispatch rule",
  "trunk_ids": [
    "<livekit_trunk_id>"
  ],
  "rule": {
    "dispatchRuleIndividual": {
      "roomPrefix": "call"
    }
  }
}
Run the command:
lk sip dispatch create dispatch-rule.json
. 3. Agent Setup: - Create an AI Voice Agent: Use the LiveKit CLI to create an AI voice agent that will join the room and interact with the caller. - Publish Audio Track: Ensure the agent publishes an audio track upon joining the room. This can be a silent track for testing purposes. 4. Testing: - Make a Call: Dial the Twilio phone number. The call should be routed through the SIP trunk to the LiveKit room. - Agent Interaction: The LiveKit agent should join the room and interact with the caller. Would you like more detailed steps on any specific part of this setup? Sources: - LiveKit SIP Quickstart - LiveKit SIP Overview 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
f
@millions-hair-24956 the suggested code to publish the audio track fails because of this error: AttributeError: module 'livekit.rtc' has no attribute 'connect'
g
If you're looking for further help, please follow-up on one of the other channels available for community support!