I have followed the voice ai agent quickstart guid...
# ask-ai
v
I have followed the voice ai agent quickstart guide and also integrated telephony to make outbound calls. How can I trigger an outbound call from my website when i enter a phonenumber in a form field there ?
t
Thanks for reaching out, Marijo. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm here to help you get started with triggering an outbound call from your website using LiveKit's telephony integration. Let's walk through the steps together: 1. Set up a SIP Trunk: First, you'll want to purchase a phone number from a SIP provider and set up the SIP trunk to accept traffic from LiveKit. This is a key step to ensure calls can be routed properly. 2. Configure Outbound Trunk: Next, create an outbound trunk in LiveKit using your SIP provider's credentials. You can easily do this through the LiveKit console or CLI—whichever you prefer. 3. Implement Outbound Call Logic: Now, using LiveKit's SDK, you can create a SIP participant and initiate the call. Here's an example in Node.js to guide you:`import { SipClient, RoomServiceClient } from 'livekit-server-sdk'; async function makeCall(phoneNumber) { const sipClient = new SipClient(LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET); const roomServiceClient = new RoomServiceClient(LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET); const roomName = `room_${Math.random()}`; await roomServiceClient.createRoom({ name: roomName }); await sipClient.createSipParticipant(SIP_OUTBOUND_TRUNK_ID, phoneNumber, roomName, { participantIdentity:
caller_${phoneNumber}
}); }` 4. Integrate with Your Website: Finally, add a simple form to your website to collect the phone number and trigger this function when the form is submitted. This will make the calling process seamless for your users. If you have any questions or need a hand with any of these steps, please don’t hesitate to reach out. I’m here to support you every step of the way! Sources: SIP trunk setup | LiveKit docs | README.md | telephony/make_call/make_call.py | Make outbound calls | LiveKit docs | Agents telephony integration | LiveKit Docs
v
how can i trigger this function ?
t
I'd be happy to help you trigger the function by integrating it into your website's backend. Here's a simple way to do it: 1. Frontend Form: You can start by creating a form on your website to collect the phone number. For example:
Copy code
<form id="callForm">
  <input type="text" id="phoneNumber" placeholder="Enter phone number" />
  <button type="button" onclick="triggerCall()">Call</button>
</form>
2. Frontend JavaScript: Next, add a JavaScript function that sends the phone number to your backend:
Copy code
function triggerCall() {
  const phoneNumber = document.getElementById('phoneNumber').value;
  fetch('/make-call', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ phoneNumber })
  });
}
3. Backend Endpoint: Finally, create an API endpoint in your backend to handle the request and call the function. For example, in Node.js:
Copy code
app.post('/make-call', async (req, res) => {
  const { phoneNumber } = req.body;
  try {
    await makeCall(phoneNumber);
    res.status(200).send('Call initiated');
  } catch (error) {
    res.status(500).send('Error initiating call');
  }
});
If you run into any questions or want me to guide you through any specific part of this integration, just let me know. I'm here to help!
v
i want to do this with python
t
I'd be happy to help you trigger the function using Python! You can set up a backend API endpoint using a framework like Flask. Here's a simple way to do it: 1. Frontend Form: First, create a form on your website to collect the phone number, just like in the earlier example. 2. Backend Endpoint: Then, use Flask to create an API endpoint that will trigger the call function. Here's an example:
Copy code
from flask import Flask, request, jsonify
from your_call_module import make_call  # Import your call function

app = Flask(__name__)

@app.route('/make-call', methods=['POST'])
def make_call_endpoint():
    data = request.get_json()
    phone_number = data.get('phoneNumber')
    try:
        make_call(phone_number)  # Call your function here
        return jsonify({'message': 'Call initiated successfully'}), 200
    except Exception as e:
        return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
    app.run(debug=True)
1. Frontend Integration: Finally, use JavaScript to send the phone number to this Python endpoint, just like we discussed earlier. If you’d like, I’m here to guide you through setting up the Python function or the Flask app—just let me know!