i was trying to integrate telephony to my livekit ...
# ask-ai
l
i was trying to integrate telephony to my livekit deployed agent for inbound calls using twilio.. can you explain step by step how to do it?? cus i tried doing it by looking at livekit docs but when called it says "sorry the call could not be connected at this moment"
t
Thanks for reaching out, Computer. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to guide you through integrating Twilio telephony with LiveKit for inbound calls! Here’s a step-by-step approach to help you get started: 1. Purchase a Phone Number: First, you’ll want to buy a phone number from Twilio via the Twilio Console. This will be the number your callers dial. 2. Set Up a TwiML Bin: Next, create a TwiML Bin in Twilio and configure it with the following TwiML: `<response> <dial> <sip>sipusernamepassword@your-livekit-sip-uri;transport=tcp</sip> </dial> </response>`Just be sure to replace
username
,
password
, and
your-livekit-sip-uri
with your actual LiveKit SIP credentials and URI. This step connects your Twilio number to LiveKit. 3. Direct Phone Number to TwiML Bin: Then, configure your Twilio phone number to use this TwiML Bin for incoming calls. You can do this under the "Voice Configuration" section in the Twilio Console. 4. Create a LiveKit Inbound Trunk: Using the LiveKit SDK, create an inbound SIP trunk. Here’s an example to make it easier: `import { SipClient } from 'livekit-server-sdk'; const sipClient = new SipClient(LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET); await sipClient.createSipInboundTrunk( 'inbound-trunk', [TWILIO_PHONE_NUMBER], { auth_username: TWILIO_SIP_USERNAME, auth_password: TWILIO_SIP_PASSWORD, } );`Feel free to reach out if you want me to walk you through this code! 5. Create a Dispatch Rule: Finally, set up a dispatch rule to route incoming callers to LiveKit rooms:
Copy code
await sipClient.createSipDispatchRule(
  {
    type: 'individual',
    roomPrefix: 'call',
  },
  {
    name: 'inbound-dispatch-rule',
    trunkIds: [trunk.sipTrunkId],
  }
);
For a full example, including setup scripts and a working project, you can check out the LiveKit SIP Agent Example. It’s a great resource to see everything in action. If you run into any bumps along the way, double-check that your TwiML Bin and LiveKit SIP credentials are set up correctly. And please don’t hesitate to ask if you need any more help — I’m here to support you! Sources: Inbound calls with Twilio Voice | LiveKit Docs | README.md
l
i tried everything as you said but a male voice said, "sorry, your call cannot be completed"
t
I'm here to help you get those calls working smoothly! Let's go through a few key things together to resolve the issue where calls can't be completed: 1. Verify Twilio SIP Trunk Configuration: Please double-check that your SIP trunk in Twilio is set up just right. The
origination URL
should be pointing to your LiveKit SIP URI using TCP transport (for example,
sip:your-livekit-sip-uri;transport=tcp
). 2. Associate Phone Number with Trunk: Make sure your Twilio phone number is linked to the SIP trunk. Without this connection, calls won’t be routed to LiveKit. 3. Check SIP Credentials: It’s important that the SIP credentials (username and password) in Twilio exactly match what you have in LiveKit. If they don’t, authentication errors can pop up. 4. Configure LiveKit Inbound Trunk and Dispatch Rule: Take a moment to verify that the inbound SIP trunk and dispatch rule in LiveKit are properly set up to accept and route calls coming from Twilio. 5. Enable Inbound Calls via TwiML: If you’re using Twilio Programmable Voice, please check that the TwiML Bin is correctly configured to redirect calls to your LiveKit SIP URI. 6. Check Regional Compliance: Sometimes calls can fail due to regional regulations. Using region pinning can help make sure you’re compliant with local laws. If you’re still running into trouble, don’t hesitate to share the exact error message or code you’re seeing (like "403 Forbidden" or "503 Service Unavailable"). I’m here to help you every step of the way! Sources: src/setup-livekit.ts | packages/sip--um-actually/README.md | SIP troubleshooting guide | LiveKit Docs | Inbound calls with Twilio Voice | LiveKit Docs