@@ -227,57 +227,19 @@ var (
227
227
Usage : "Create a SIP Dispatch Rule" ,
228
228
Action : createSIPDispatchRule ,
229
229
ArgsUsage : RequestDesc [livekit.CreateSIPDispatchRuleRequest ](),
230
- Flags : []cli.Flag {
231
- & cli.StringFlag {
232
- Name : "name" ,
233
- Usage : "Sets a new name for the dispatch rule" ,
234
- },
235
- & cli.StringSliceFlag {
236
- Name : "trunks" ,
237
- Usage : "Sets a list of trunks for the dispatch rule" ,
238
- },
239
- & cli.StringFlag {
240
- Name : "direct" ,
241
- Usage : "Sets a direct dispatch to a specified room" ,
242
- },
243
- & cli.StringFlag {
244
- Name : "caller" ,
245
- Aliases : []string {"individual" },
246
- Usage : "Sets a individual caller dispatch to a new room with a specific prefix" ,
247
- },
248
- & cli.StringFlag {
249
- Name : "callee" ,
250
- Usage : "Sets a callee number dispatch to a new room with a specific prefix" ,
251
- },
252
- & cli.BoolFlag {
253
- Name : "pin" ,
254
- Usage : "PIN for a dispatch rule" ,
255
- },
256
- & cli.BoolFlag {
257
- Name : "randomize" ,
258
- Usage : "Randomize room name, only applies to callee dispatch" ,
259
- },
260
- },
230
+ Flags : sipDispatchRuleBaseFlags ,
261
231
},
262
232
{
263
233
Name : "update" ,
264
234
Usage : "Update a SIP Dispatch Rule" ,
265
235
Action : updateSIPDispatchRule ,
266
236
ArgsUsage : RequestDesc [livekit.UpdateSIPDispatchRuleRequest ](),
267
- Flags : []cli.Flag {
237
+ Flags : append ( []cli.Flag {
268
238
& cli.StringFlag {
269
239
Name : "id" ,
270
240
Usage : "ID for the rule to update" ,
271
241
},
272
- & cli.StringFlag {
273
- Name : "name" ,
274
- Usage : "Sets a new name for the rule" ,
275
- },
276
- & cli.StringSliceFlag {
277
- Name : "trunks" ,
278
- Usage : "Sets a new list of trunk IDs" ,
279
- },
280
- },
242
+ }, sipDispatchRuleBaseFlags ... ),
281
243
},
282
244
{
283
245
Name : "delete" ,
@@ -413,6 +375,47 @@ var (
413
375
},
414
376
},
415
377
}
378
+
379
+ // Define a shared base flag list for SIP Dispatch Rule create/update
380
+ sipDispatchRuleBaseFlags = []cli.Flag {
381
+ & cli.StringFlag {
382
+ Name : "name" ,
383
+ Usage : "Sets a name for the dispatch rule" ,
384
+ },
385
+ & cli.StringSliceFlag {
386
+ Name : "trunks" ,
387
+ Usage : "Sets a list of trunks for the dispatch rule" ,
388
+ },
389
+ & cli.StringFlag {
390
+ Name : "direct" ,
391
+ Usage : "Sets a direct dispatch to a specified room" ,
392
+ },
393
+ & cli.StringFlag {
394
+ Name : "caller" ,
395
+ Aliases : []string {"individual" },
396
+ Usage : "Sets an individual caller dispatch to a new room with a specific prefix" ,
397
+ },
398
+ & cli.StringFlag {
399
+ Name : "callee" ,
400
+ Usage : "Sets a callee number dispatch to a new room with a specific prefix" ,
401
+ },
402
+ & cli.BoolFlag {
403
+ Name : "pin" ,
404
+ Usage : "PIN for a dispatch rule" ,
405
+ },
406
+ & cli.BoolFlag {
407
+ Name : "randomize" ,
408
+ Usage : "Randomize room name, only applies to callee dispatch" ,
409
+ },
410
+ & cli.StringFlag {
411
+ Name : "dispatch-url" ,
412
+ Usage : "Sets a dynamic dispatch rule with webhook URL (uses POST method)" ,
413
+ },
414
+ & cli.StringFlag {
415
+ Name : "method" ,
416
+ Usage : "Sets the HTTP method for dynamic dispatch rule (default: POST)" ,
417
+ },
418
+ }
416
419
)
417
420
418
421
func listUpdateFlag (cmd * cli.Command , setName string ) * livekit.ListUpdate {
@@ -895,6 +898,23 @@ func createSIPDispatchRule(ctx context.Context, cmd *cli.Command) error {
895
898
},
896
899
}
897
900
}
901
+ if val := cmd .String ("dispatch-url" ); val != "" {
902
+ if p .Rule != nil {
903
+ return fmt .Errorf ("only one dispatch rule type is allowed" )
904
+ }
905
+ method := cmd .String ("method" )
906
+ if method == "" {
907
+ method = "POST"
908
+ }
909
+ p .Rule = & livekit.SIPDispatchRule {
910
+ Rule : & livekit.SIPDispatchRule_DispatchRuleDynamic {
911
+ DispatchRuleDynamic : & livekit.SIPDispatchRuleDynamic {
912
+ Url : val ,
913
+ Method : method ,
914
+ },
915
+ },
916
+ }
917
+ }
898
918
return nil
899
919
}, cli .CreateSIPDispatchRule , printSIPDispatchRuleID )
900
920
}
@@ -945,6 +965,71 @@ func updateSIPDispatchRule(ctx context.Context, cmd *cli.Command) error {
945
965
if id == "" {
946
966
return errors .New ("no ID specified" )
947
967
}
968
+
969
+ // Check if any dispatch rule flags are set
970
+ hasDispatchRuleFlags := cmd .IsSet ("direct" ) || cmd .IsSet ("caller" ) || cmd .IsSet ("callee" ) || cmd .IsSet ("dispatch-url" )
971
+
972
+ if hasDispatchRuleFlags {
973
+ // Create a new dispatch rule from flags (similar to create function)
974
+ rule := & livekit.SIPDispatchRule {}
975
+
976
+ if val := cmd .String ("direct" ); val != "" {
977
+ rule .Rule = & livekit.SIPDispatchRule_DispatchRuleDirect {
978
+ DispatchRuleDirect : & livekit.SIPDispatchRuleDirect {
979
+ RoomName : val ,
980
+ Pin : cmd .String ("pin" ),
981
+ },
982
+ }
983
+ } else if val := cmd .String ("caller" ); val != "" {
984
+ rule .Rule = & livekit.SIPDispatchRule_DispatchRuleIndividual {
985
+ DispatchRuleIndividual : & livekit.SIPDispatchRuleIndividual {
986
+ RoomPrefix : val ,
987
+ Pin : cmd .String ("pin" ),
988
+ },
989
+ }
990
+ } else if val := cmd .String ("callee" ); val != "" {
991
+ rule .Rule = & livekit.SIPDispatchRule_DispatchRuleCallee {
992
+ DispatchRuleCallee : & livekit.SIPDispatchRuleCallee {
993
+ RoomPrefix : val ,
994
+ Randomize : cmd .Bool ("randomize" ),
995
+ Pin : cmd .String ("pin" ),
996
+ },
997
+ }
998
+ } else if val := cmd .String ("dispatch-url" ); val != "" {
999
+ method := cmd .String ("method" )
1000
+ if method == "" {
1001
+ method = "POST"
1002
+ }
1003
+ rule .Rule = & livekit.SIPDispatchRule_DispatchRuleDynamic {
1004
+ DispatchRuleDynamic : & livekit.SIPDispatchRuleDynamic {
1005
+ Url : val ,
1006
+ Method : method ,
1007
+ },
1008
+ }
1009
+ }
1010
+
1011
+ // Use Update action with the rule field populated
1012
+ req := & livekit.SIPDispatchRuleUpdate {
1013
+ Rule : rule ,
1014
+ }
1015
+ if val := cmd .String ("name" ); val != "" {
1016
+ req .Name = & val
1017
+ }
1018
+ req .TrunkIds = listUpdateFlag (cmd , "trunks" )
1019
+
1020
+ info , err := cli .UpdateSIPDispatchRule (ctx , & livekit.UpdateSIPDispatchRuleRequest {
1021
+ SipDispatchRuleId : id ,
1022
+ Action : & livekit.UpdateSIPDispatchRuleRequest_Update {
1023
+ Update : req ,
1024
+ },
1025
+ })
1026
+ if err != nil {
1027
+ return err
1028
+ }
1029
+ printSIPDispatchRuleID (info )
1030
+ return err
1031
+ }
1032
+
948
1033
req := & livekit.SIPDispatchRuleUpdate {}
949
1034
if val := cmd .String ("name" ); val != "" {
950
1035
req .Name = & val
@@ -969,10 +1054,10 @@ func listSipDispatchRule(ctx context.Context, cmd *cli.Command) error {
969
1054
return err
970
1055
}
971
1056
return listAndPrint (ctx , cmd , cli .ListSIPDispatchRule , & livekit.ListSIPDispatchRuleRequest {}, []string {
972
- "SipDispatchRuleID" , "Name" , "SipTrunks" , "Type" , "RoomName" , "Pin" ,
1057
+ "SipDispatchRuleID" , "Name" , "SipTrunks" , "Type" , "RoomName" , "Pin" , "DispatchURL" ,
973
1058
"Attributes" , "Agents" ,
974
1059
}, func (item * livekit.SIPDispatchRuleInfo ) []string {
975
- var room , typ , pin string
1060
+ var room , typ , pin , dispatchUrl string
976
1061
switch r := item .GetRule ().GetRule ().(type ) {
977
1062
case * livekit.SIPDispatchRule_DispatchRuleDirect :
978
1063
room = r .DispatchRuleDirect .RoomName
@@ -989,6 +1074,10 @@ func listSipDispatchRule(ctx context.Context, cmd *cli.Command) error {
989
1074
}
990
1075
pin = r .DispatchRuleCallee .Pin
991
1076
typ = "Callee"
1077
+ case * livekit.SIPDispatchRule_DispatchRuleDynamic :
1078
+ room = ""
1079
+ dispatchUrl = r .DispatchRuleDynamic .Url
1080
+ typ = "Dynamic"
992
1081
}
993
1082
trunks := strings .Join (item .TrunkIds , "," )
994
1083
if trunks == "" {
@@ -1001,7 +1090,7 @@ func listSipDispatchRule(ctx context.Context, cmd *cli.Command) error {
1001
1090
}
1002
1091
}
1003
1092
return []string {
1004
- item .SipDispatchRuleId , item .Name , trunks , typ , room , pin ,
1093
+ item .SipDispatchRuleId , item .Name , trunks , typ , room , pin , dispatchUrl ,
1005
1094
fmt .Sprintf ("%v" , item .Attributes ), strings .Join (agents , "," ),
1006
1095
}
1007
1096
})
0 commit comments