How to make bulk calls
# ask-ai
b
How to make bulk calls
t
Thanks for reaching out, Sanika. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to make bulk calls in LiveKit, you can totally use the SIP participant creation API. Let me walk you through it step-by-step: 1. Prepare Your Data: Start by creating a CSV file with phone numbers and any extra info you want to include. For example:
Copy code
phone_number,question
+1234567890,Hello! How are you today?
+9876543210,This is a test call.
2. Use the Python Example: You can use a script to read your CSV and make the calls. The script will create a room, dispatch, and a SIP participant for each call. Here’s a quick example:
Copy code
async def make_survey_call(phone_number, question, row_index):
    room_name = f"room_{row_index}"
    metadata = json.dumps({"phone_number": phone_number, "question": question})
    sip_participant = await lkapi.sip.create_sip_participant(
        api.CreateSIPParticipantRequest(
            room_name=room_name,
            sip_trunk_id=outbound_trunk_id,
            sip_call_to=phone_number,
            participant_identity="phone_user"))
3. Process the CSV: Just read through your CSV and kick off calls for each row. 4. Set Environment Variables: Make sure you’ve got these set up: ◦ LIVEKIT_API_KEY ◦ LIVEKIT_API_SECRET ◦ LIVEKIT_URL ◦ SIP_OUTBOUND_TRUNK_ID 1. Run the Script: Run your script with all the right dependencies, and don’t forget to handle things like rate limits, errors, and retries so everything goes smoothly. If you hit any bumps or want me to help you with the implementation, just give me a shout—I’m here for you!
Hey there! Here’s a handy Python script to help you make bulk calls using LiveKit with a CSV file named
sample.csv
. Just make sure you have the necessary dependencies and environment variables set up as explained below: 1. Install Dependencies: Simply run
pip install livekit python-dotenv
to get started. 2. Create a .env File: Pop in your LiveKit credentials like this:
Copy code
LIVEKIT_URL=<your_livekit_server_url>
LIVEKIT_API_KEY=<your_api_key>
LIVEKIT_API_SECRET=<your_api_secret>
SIP_OUTBOUND_TRUNK_ID=<your_sip_outbound_trunk_id>
3. CSV File Format: Make sure your
sample.csv
looks like this:
Copy code
Phone Number,Question,Answer,Status
+1231231231,Do you prefer chocolate or vanilla ice cream?,,
Here’s the script for you:
Copy code
import asyncio
import csv
import json
import os
from dotenv import load_dotenv
from livekit import api

load_dotenv()

async def make_call(phone_number, question, row_index):
    room_name = f"bulk-call-{row_index}"
    metadata = json.dumps({"phone_number": phone_number, "question": question})
    lkapi = api.LiveKitAPI()
    await lkapi.sip.create_sip_participant(api.CreateSIPParticipantRequest(
        room_name=room_name,
        sip_trunk_id=os.getenv("SIP_OUTBOUND_TRUNK_ID"),
        sip_call_to=phone_number,
        participant_identity="phone_user"))
    await lkapi.aclose()

async def process_calls():
    with open("sample.csv", "r") as f:
        reader = csv.DictReader(f)
        for i, row in enumerate(reader):
            if not row["Answer"]:
                await make_call(row["Phone Number"], row["Question"], i+1)

asyncio.run(process_calls())
Just save this as
bulk_caller.py
and run it with
python3 bulk_caller.py
. If you hit any bumps or have questions, feel free to ask—I’m here to help!
b
Give me script for the same and let the name be sample.csv
t
Hey there! Here’s a handy Python script to help you make bulk calls using LiveKit with a CSV file named
sample.csv
. Just make sure you have everything set up as described below—it’s pretty straightforward! 1. Install Dependencies: Simply run
pip install livekit python-dotenv
to get what you need. 2. Create a .env File: Pop in your LiveKit credentials like this:
Copy code
LIVEKIT_URL=<your_livekit_server_url>
LIVEKIT_API_KEY=<your_api_key>
LIVEKIT_API_SECRET=<your_api_secret>
SIP_OUTBOUND_TRUNK_ID=<your_sip_outbound_trunk_id>
3. CSV File Format: Make sure your
sample.csv
looks like this:
Copy code
Phone Number,Question,Answer,Status
+1231231231,Do you prefer chocolate or vanilla ice cream?,,
Here’s the script for you to use:
Copy code
import asyncio
import csv
import json
import os
from dotenv import load_dotenv
from livekit import api

load_dotenv()

async def make_call(phone_number, question, row_index):
    room_name = f"bulk-call-{row_index}"
    metadata = json.dumps({"phone_number": phone_number, "question": question})
    lkapi = api.LiveKitAPI()
    await lkapi.sip.create_sip_participant(api.CreateSIPParticipantRequest(
        room_name=room_name,
        sip_trunk_id=os.getenv("SIP_OUTBOUND_TRUNK_ID"),
        sip_call_to=phone_number,
        participant_identity="phone_user"))
    await lkapi.aclose()

async def process_calls():
    with open("sample.csv", "r") as f:
        reader = csv.DictReader(f)
        for i, row in enumerate(reader):
            if not row["Answer"]:
                await make_call(row["Phone Number"], row["Question"], i+1)

asyncio.run(process_calls())
Just save this as
bulk_caller.py
and run it using
python3 bulk_caller.py
. If you hit any snags or want to chat more about it, I’m here to help!
b
If I am making 50 concurrent call will I also need 50 worker nodes
t
Hey there! You actually don’t need 50 worker nodes for 50 concurrent calls in LiveKit. How many nodes you’ll need really depends on a few things: • Resource Requirements: Stuff like video quality, bitrate, and how many audio/video tracks you have all play a role in how much load each node handles. • LiveKit Architecture: Each room runs on a single node, but if your resources allow, multiple rooms can share a node. • Load Testing: It’s a great idea to use LiveKit’s benchmarking tools to simulate your workload and see if one node can handle all 50 calls. • Distributed Setup: If you’re planning for growth or want some backup, a distributed setup is worth considering—but you don’t need a one-to-one ratio of nodes to calls. Need a hand with running those benchmarks or setting up a distributed environment? I’m here to help!