@@ -16,25 +16,25 @@ def get_env_var(var_name):
1616 return value
1717
1818
19- def create_livekit_trunk (client , sip_uri ):
19+ def create_livekit_trunk (client , sip_uri , trunk_name ):
2020 domain_name = f"livekit-trunk-{ os .urandom (4 ).hex ()} .pstn.twilio.com"
2121 trunk = client .trunking .v1 .trunks .create (
22- friendly_name = "LiveKit Trunk" ,
22+ friendly_name = trunk_name ,
2323 domain_name = domain_name ,
2424 )
2525 trunk .origination_urls .create (
2626 sip_url = sip_uri ,
2727 weight = 1 ,
2828 priority = 1 ,
2929 enabled = True ,
30- friendly_name = "LiveKit SIP URI" ,
30+ friendly_name = f" { trunk_name } SIP URI" ,
3131 )
32- logging .info ("Created new LiveKit Trunk ." )
32+ logging .info (f "Created new { trunk_name } trunk ." )
3333 return trunk
3434
3535
36- def create_inbound_trunk (phone_number ):
37- trunk_data = {"trunk" : {"name" : "Inbound LiveKit Trunk " , "numbers" : [phone_number ]}}
36+ def create_inbound_trunk (phone_number , trunk_name ):
37+ trunk_data = {"trunk" : {"name" : f "Inbound { trunk_name } " , "numbers" : [phone_number ]}}
3838 with open ("inbound_trunk.json" , "w" ) as f :
3939 json .dump (trunk_data , f , indent = 4 )
4040
@@ -58,9 +58,9 @@ def create_inbound_trunk(phone_number):
5858 return None
5959
6060
61- def create_dispatch_rule (trunk_sid ):
61+ def create_dispatch_rule (trunk_sid , trunk_name ):
6262 dispatch_rule_data = {
63- "name" : "Inbound Dispatch Rule" ,
63+ "name" : f "Inbound { trunk_name } Dispatch Rule" ,
6464 "trunk_ids" : [trunk_sid ],
6565 "rule" : {"dispatchRuleIndividual" : {"roomPrefix" : "call-" }},
6666 }
@@ -89,23 +89,25 @@ def main():
8989 auth_token = get_env_var ("TWILIO_AUTH_TOKEN" )
9090 phone_number = get_env_var ("TWILIO_PHONE_NUMBER" )
9191 sip_uri = get_env_var ("LIVEKIT_SIP_URI" )
92+ trunk_name = get_env_var ("TRUNK_NAME" )
9293
9394 client = Client (account_sid , auth_token )
9495
9596 existing_trunks = client .trunking .v1 .trunks .list ()
9697 livekit_trunk = next (
97- (trunk for trunk in existing_trunks if trunk .friendly_name == "LiveKit Trunk" ),
98+ (trunk for trunk in existing_trunks if trunk .friendly_name == trunk_name ),
9899 None ,
99100 )
100101
101102 if not livekit_trunk :
102- livekit_trunk = create_livekit_trunk (client , sip_uri )
103+ livekit_trunk = create_livekit_trunk (client , sip_uri , trunk_name )
103104 else :
104- logging .info ("LiveKit Trunk already exists. Using the existing trunk." )
105+ logging .info (f" { trunk_name } already exists. Using the existing trunk." )
105106
106- inbound_trunk_sid = create_inbound_trunk (phone_number )
107+
108+ inbound_trunk_sid = create_inbound_trunk (phone_number , trunk_name )
107109 if inbound_trunk_sid :
108- create_dispatch_rule (inbound_trunk_sid )
110+ create_dispatch_rule (inbound_trunk_sid , trunk_name )
109111
110112
111113if __name__ == "__main__" :
0 commit comments