Add way to specify phone number

This commit is contained in:
James Hush
2024-12-10 15:27:38 +08:00
parent 875ecf7fcb
commit 6377825cff
3 changed files with 26 additions and 19 deletions

View File

@@ -25,12 +25,13 @@ daily_api_url = os.getenv("DAILY_API_URL", "https://api.daily.co/v1")
class DialoutBot:
def __init__(self, room_url: str, token: str, callId: int, run_number: int):
def __init__(self, room_url: str, token: str, callId: int, run_number: int, phone_number: str):
self.recording_id = None
self.room_url = room_url
self.token = token
self.callId = callId
self.run_number = run_number
self.phone_number = phone_number
async def run(self):
transport = DailyTransport(
@@ -80,20 +81,21 @@ class DialoutBot:
task = PipelineTask(pipeline, PipelineParams(allow_interruptions=True))
def get_phone_number(callId: int, run_number: int) -> str:
if self.phone_number:
return self.phone_number
if run_number % 2 == 0:
phone_numbers = [
"+12097743694", # James (Daily Pipecat Local Computer)
# "+12097135124", # James
# "+12097135125", # James
# "+19499870006", # Varun
"+12097135124", # James
"+12097135125", # James
"+19499870006", # Varun
]
return phone_numbers[callId % len(phone_numbers)]
else:
phone_numbers = [
"+12097743694", # James (Daily Pipecat Local Computer)
# "+14155204406", # James
# "+18187229086", # James (Avoca)
# "+16673870006", # Varun
"+14155204406", # James
"+18187229086", # James (Avoca)
"+16673870006", # Varun
]
return phone_numbers[callId % len(phone_numbers)]
@@ -195,9 +197,10 @@ if __name__ == "__main__":
parser.add_argument("-t", type=str, help="Token")
parser.add_argument("-i", type=str, help="Call ID")
parser.add_argument("-r", type=str, help="Run Number")
parser.add_argument("-p", type=str, help="Phone Number")
config = parser.parse_args()
bot = DialoutBot(config.u, config.t, int(config.i), int(config.r))
bot = DialoutBot(config.u, config.t, int(config.i), int(config.r), config.p)
try:
asyncio.run(bot.run())

View File

@@ -14,10 +14,8 @@ from pipecat.transports.services.helpers.daily_rest import (
DailyRoomProperties,
)
BOT_RUN_TIME = 300
async def run_bot(id: int, run_number: int, bot_run_time: int, csv_writer):
async def run_bot(id: int, run_number: int, bot_run_time: int, phone_number: str, csv_writer):
async with aiohttp.ClientSession() as aiohttp_session:
print(f"Starting bot number: {id}")
rest = DailyRESTHelper(
@@ -27,7 +25,7 @@ async def run_bot(id: int, run_number: int, bot_run_time: int, csv_writer):
)
# Create daily.co room with dialin and dialout enabled
exp = time.time() + BOT_RUN_TIME
exp = time.time() + bot_run_time
room_params = DailyRoomParams(
properties=DailyRoomProperties(
exp=exp,
@@ -61,7 +59,7 @@ async def run_bot(id: int, run_number: int, bot_run_time: int, csv_writer):
[id, "Rate Limit Error", datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]]
)
bot_proc = f"python3 -m batch_dialout_bot -u {room.url} -t {token} -i {id} -r {run_number}"
bot_proc = f"python3 -m batch_dialout_bot -u {room.url} -t {token} -i {id} -r {run_number} -p {phone_number}"
try:
subprocess.Popen(
@@ -76,11 +74,13 @@ async def main():
parser.add_argument("-b", type=int, help="Number of bots per run")
parser.add_argument("-r", type=int, help="Number of runs")
parser.add_argument("-t", type=int, help="Time to run the bot in seconds")
parser.add_argument("-p", type=str, help="Phone Number")
config = parser.parse_args()
number_of_batches = int(config.r)
number_of_bots = int(config.b)
bot_run_time = int(config.t)
phone_number = config.p
# Open the CSV file in append mode
with open("output.csv", mode="w", newline="") as file:
@@ -90,11 +90,14 @@ async def main():
for run_number in range(number_of_batches):
print(f"-- Starting batch run number: {run_number} of {number_of_batches}")
bots = [run_bot(i, run_number, bot_run_time, csv_writer) for i in range(number_of_bots)]
bots = [
run_bot(i, run_number, bot_run_time, phone_number, csv_writer)
for i in range(number_of_bots)
]
print(f"-- Number of bots: {len(bots)}")
await asyncio.gather(*bots)
print(f"-- Waiting {bot_run_time} seconds...")
await asyncio.sleep(bot_run_time)
print(f"-- Waiting {bot_run_time + 30} seconds...")
await asyncio.sleep(bot_run_time + 30)
print(f"-- Finished waiting {bot_run_time} seconds...")

View File

@@ -1,2 +1,3 @@
bot_id,enable_dialout,timestamp
0,True,2024-12-10 14:57:45.708
0,True,2024-12-10 15:24:10.529
0,True,2024-12-10 15:24:51.754
1 bot_id enable_dialout timestamp
2 0 True 2024-12-10 14:57:45.708 2024-12-10 15:24:10.529
3 0 True 2024-12-10 15:24:51.754