@@ -15,6 +15,7 @@ def get_env_var(var_name):
1515 exit (1 )
1616 return value
1717
18+
1819def create_livekit_trunk (client , sip_uri ):
1920 domain_name = f"livekit-trunk-{ os .urandom (4 ).hex ()} .pstn.twilio.com"
2021 trunk = client .trunking .v1 .trunks .create (
@@ -31,20 +32,17 @@ def create_livekit_trunk(client, sip_uri):
3132 logging .info ("Created new LiveKit Trunk." )
3233 return trunk
3334
35+
3436def create_inbound_trunk (phone_number ):
35- trunk_data = {
36- "trunk" : {
37- "name" : "Inbound LiveKit Trunk" ,
38- "numbers" : [phone_number ]
39- }
40- }
37+ trunk_data = {"trunk" : {"name" : "Inbound LiveKit Trunk" , "numbers" : [phone_number ]}}
4138 with open ("inbound_trunk.json" , "w" ) as f :
4239 json .dump (trunk_data , f , indent = 4 )
4340
4441 result = subprocess .run (
4542 ["lk" , "sip" , "inbound" , "create" , "inbound_trunk.json" ],
4643 capture_output = True ,
47- text = True , check = False
44+ text = True ,
45+ check = False ,
4846 )
4947
5048 if result .returncode != 0 :
@@ -59,23 +57,21 @@ def create_inbound_trunk(phone_number):
5957 logging .error ("Could not find inbound trunk SID in output." )
6058 return None
6159
60+
6261def create_dispatch_rule (trunk_sid ):
6362 dispatch_rule_data = {
6463 "name" : "Inbound Dispatch Rule" ,
6564 "trunk_ids" : [trunk_sid ],
66- "rule" : {
67- "dispatchRuleIndividual" : {
68- "roomPrefix" : "call-"
69- }
70- }
65+ "rule" : {"dispatchRuleIndividual" : {"roomPrefix" : "call-" }},
7166 }
7267 with open ("dispatch_rule.json" , "w" ) as f :
7368 json .dump (dispatch_rule_data , f , indent = 4 )
7469
7570 result = subprocess .run (
7671 ["lk" , "sip" , "dispatch-rule" , "create" , "dispatch_rule.json" ],
7772 capture_output = True ,
78- text = True , check = False
73+ text = True ,
74+ check = False ,
7975 )
8076
8177 if result .returncode != 0 :
@@ -84,6 +80,7 @@ def create_dispatch_rule(trunk_sid):
8480
8581 logging .info (f"Dispatch rule created: { result .stdout } " )
8682
83+
8784def main ():
8885 load_dotenv ()
8986 logging .basicConfig (level = logging .INFO )
@@ -98,7 +95,7 @@ def main():
9895 existing_trunks = client .trunking .v1 .trunks .list ()
9996 livekit_trunk = next (
10097 (trunk for trunk in existing_trunks if trunk .friendly_name == "LiveKit Trunk" ),
101- None
98+ None ,
10299 )
103100
104101 if not livekit_trunk :
@@ -110,5 +107,6 @@ def main():
110107 if inbound_trunk_sid :
111108 create_dispatch_rule (inbound_trunk_sid )
112109
110+
113111if __name__ == "__main__" :
114112 main ()
0 commit comments