Add way to specify phone number
This commit is contained in:
@@ -25,12 +25,13 @@ daily_api_url = os.getenv("DAILY_API_URL", "https://api.daily.co/v1")
|
|||||||
|
|
||||||
|
|
||||||
class DialoutBot:
|
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.recording_id = None
|
||||||
self.room_url = room_url
|
self.room_url = room_url
|
||||||
self.token = token
|
self.token = token
|
||||||
self.callId = callId
|
self.callId = callId
|
||||||
self.run_number = run_number
|
self.run_number = run_number
|
||||||
|
self.phone_number = phone_number
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
transport = DailyTransport(
|
transport = DailyTransport(
|
||||||
@@ -80,20 +81,21 @@ class DialoutBot:
|
|||||||
task = PipelineTask(pipeline, PipelineParams(allow_interruptions=True))
|
task = PipelineTask(pipeline, PipelineParams(allow_interruptions=True))
|
||||||
|
|
||||||
def get_phone_number(callId: int, run_number: int) -> str:
|
def get_phone_number(callId: int, run_number: int) -> str:
|
||||||
|
if self.phone_number:
|
||||||
|
return self.phone_number
|
||||||
|
|
||||||
if run_number % 2 == 0:
|
if run_number % 2 == 0:
|
||||||
phone_numbers = [
|
phone_numbers = [
|
||||||
"+12097743694", # James (Daily Pipecat Local Computer)
|
"+12097135124", # James
|
||||||
# "+12097135124", # James
|
"+12097135125", # James
|
||||||
# "+12097135125", # James
|
"+19499870006", # Varun
|
||||||
# "+19499870006", # Varun
|
|
||||||
]
|
]
|
||||||
return phone_numbers[callId % len(phone_numbers)]
|
return phone_numbers[callId % len(phone_numbers)]
|
||||||
else:
|
else:
|
||||||
phone_numbers = [
|
phone_numbers = [
|
||||||
"+12097743694", # James (Daily Pipecat Local Computer)
|
"+14155204406", # James
|
||||||
# "+14155204406", # James
|
"+18187229086", # James (Avoca)
|
||||||
# "+18187229086", # James (Avoca)
|
"+16673870006", # Varun
|
||||||
# "+16673870006", # Varun
|
|
||||||
]
|
]
|
||||||
return phone_numbers[callId % len(phone_numbers)]
|
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("-t", type=str, help="Token")
|
||||||
parser.add_argument("-i", type=str, help="Call ID")
|
parser.add_argument("-i", type=str, help="Call ID")
|
||||||
parser.add_argument("-r", type=str, help="Run Number")
|
parser.add_argument("-r", type=str, help="Run Number")
|
||||||
|
parser.add_argument("-p", type=str, help="Phone Number")
|
||||||
config = parser.parse_args()
|
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:
|
try:
|
||||||
asyncio.run(bot.run())
|
asyncio.run(bot.run())
|
||||||
|
|||||||
@@ -14,10 +14,8 @@ from pipecat.transports.services.helpers.daily_rest import (
|
|||||||
DailyRoomProperties,
|
DailyRoomProperties,
|
||||||
)
|
)
|
||||||
|
|
||||||
BOT_RUN_TIME = 300
|
|
||||||
|
|
||||||
|
async def run_bot(id: int, run_number: int, bot_run_time: int, phone_number: str, csv_writer):
|
||||||
async def run_bot(id: int, run_number: int, bot_run_time: int, csv_writer):
|
|
||||||
async with aiohttp.ClientSession() as aiohttp_session:
|
async with aiohttp.ClientSession() as aiohttp_session:
|
||||||
print(f"Starting bot number: {id}")
|
print(f"Starting bot number: {id}")
|
||||||
rest = DailyRESTHelper(
|
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
|
# Create daily.co room with dialin and dialout enabled
|
||||||
exp = time.time() + BOT_RUN_TIME
|
exp = time.time() + bot_run_time
|
||||||
room_params = DailyRoomParams(
|
room_params = DailyRoomParams(
|
||||||
properties=DailyRoomProperties(
|
properties=DailyRoomProperties(
|
||||||
exp=exp,
|
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]]
|
[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:
|
try:
|
||||||
subprocess.Popen(
|
subprocess.Popen(
|
||||||
@@ -76,11 +74,13 @@ async def main():
|
|||||||
parser.add_argument("-b", type=int, help="Number of bots per run")
|
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("-r", type=int, help="Number of runs")
|
||||||
parser.add_argument("-t", type=int, help="Time to run the bot in seconds")
|
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()
|
config = parser.parse_args()
|
||||||
|
|
||||||
number_of_batches = int(config.r)
|
number_of_batches = int(config.r)
|
||||||
number_of_bots = int(config.b)
|
number_of_bots = int(config.b)
|
||||||
bot_run_time = int(config.t)
|
bot_run_time = int(config.t)
|
||||||
|
phone_number = config.p
|
||||||
|
|
||||||
# Open the CSV file in append mode
|
# Open the CSV file in append mode
|
||||||
with open("output.csv", mode="w", newline="") as file:
|
with open("output.csv", mode="w", newline="") as file:
|
||||||
@@ -90,11 +90,14 @@ async def main():
|
|||||||
|
|
||||||
for run_number in range(number_of_batches):
|
for run_number in range(number_of_batches):
|
||||||
print(f"-- Starting batch run number: {run_number} of {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)}")
|
print(f"-- Number of bots: {len(bots)}")
|
||||||
await asyncio.gather(*bots)
|
await asyncio.gather(*bots)
|
||||||
print(f"-- Waiting {bot_run_time} seconds...")
|
print(f"-- Waiting {bot_run_time + 30} seconds...")
|
||||||
await asyncio.sleep(bot_run_time)
|
await asyncio.sleep(bot_run_time + 30)
|
||||||
print(f"-- Finished waiting {bot_run_time} seconds...")
|
print(f"-- Finished waiting {bot_run_time} seconds...")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
bot_id,enable_dialout,timestamp
|
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
|
||||||
|
|||||||
|
Reference in New Issue
Block a user