Skip to content

Commit 84f14a4

Browse files
Incorporating changes in the list phone number api
1 parent 1454db9 commit 84f14a4

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

cmd/lk/phone_number.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,17 @@ var (
7676
Flags: []cli.Flag{
7777
&cli.IntFlag{
7878
Name: "limit",
79-
Usage: "Maximum number of results (default: 50)",
79+
Usage: "Maximum number of results per page (default: 50)",
8080
Value: 50,
8181
},
82+
&cli.IntFlag{
83+
Name: "offset",
84+
Usage: "Offset for pagination (default: 0)",
85+
Value: 0,
86+
},
8287
&cli.StringSliceFlag{
8388
Name: "status",
84-
Usage: "Filter by status(es) (active, pending, released). Mutliple values can be specified.",
89+
Usage: "Filter by status(es) (active, pending, released, offline). Multiple values can be specified.",
8590
},
8691
&cli.StringFlag{
8792
Name: "sip-dispatch-rule-id",
@@ -351,10 +356,17 @@ func listPhoneNumbers(ctx context.Context, cmd *cli.Command) error {
351356
}
352357

353358
req := &livekit.ListPhoneNumbersRequest{}
354-
if val := cmd.Int("limit"); val != 0 {
355-
limit := int32(val)
356-
req.Limit = &limit
359+
limit := int32(cmd.Int("limit"))
360+
offset := int32(cmd.Int("offset"))
361+
362+
// Encode offset and limit into a page token for pagination
363+
// Even if offset is 0, we encode it to include the limit in the token
364+
pageToken, err := livekit.EncodeTokenPagination(offset, limit)
365+
if err != nil {
366+
return fmt.Errorf("failed to encode pagination token: %w", err)
357367
}
368+
req.PageToken = pageToken
369+
358370
if statuses := cmd.StringSlice("status"); len(statuses) > 0 {
359371
var phoneNumberStatuses []livekit.PhoneNumberStatus
360372
for _, status := range statuses {
@@ -418,7 +430,23 @@ func listPhoneNumbers(ctx context.Context, cmd *cli.Command) error {
418430
return nil
419431
}
420432

421-
fmt.Printf("Total phone numbers: %d\n", resp.TotalCount)
433+
fmt.Printf("Total phone numbers: %d", resp.TotalCount)
434+
if resp.OfflineCount > 0 {
435+
fmt.Printf(" (%d offline)", resp.OfflineCount)
436+
}
437+
fmt.Printf("\n")
438+
439+
// Show pagination info
440+
if offset > 0 {
441+
fmt.Printf("Showing results from offset %d\n", offset)
442+
}
443+
if resp.NextPageToken != nil {
444+
nextOffset, _, err := livekit.DecodeTokenPagination(resp.NextPageToken)
445+
if err == nil {
446+
fmt.Printf("More results available. Use --offset %d to see the next page.\n", nextOffset)
447+
}
448+
}
449+
422450
return listAndPrint(ctx, cmd, func(ctx context.Context, req *livekit.ListPhoneNumbersRequest) (*livekit.ListPhoneNumbersResponse, error) {
423451
return client.ListPhoneNumbers(ctx, req)
424452
}, req, []string{

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/go-logr/logr v1.4.3
1313
github.com/go-task/task/v3 v3.44.1
1414
github.com/joho/godotenv v1.5.1
15-
github.com/livekit/protocol v1.43.1-0.20251112192040-8bdcb749c402
15+
github.com/livekit/protocol v1.43.3-0.20251127030154-5d65f30ee664
1616
github.com/livekit/server-sdk-go/v2 v2.12.9-0.20251112193538-ed23dded48f9
1717
github.com/moby/patternmatcher v0.6.0
1818
github.com/pelletier/go-toml v1.9.5
@@ -113,7 +113,7 @@ require (
113113
github.com/lithammer/shortuuid/v4 v4.2.0 // indirect
114114
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 // indirect
115115
github.com/livekit/mediatransportutil v0.0.0-20250922175932-f537f0880397 // indirect
116-
github.com/livekit/psrpc v0.7.1-0.20251105165826-1016ad610a7e // indirect
116+
github.com/livekit/psrpc v0.7.1 // indirect
117117
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
118118
github.com/magefile/mage v1.15.0 // indirect
119119
github.com/mattn/go-colorable v0.1.14 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5AT
267267
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
268268
github.com/livekit/mediatransportutil v0.0.0-20250922175932-f537f0880397 h1:Z7j2mY+bvG05UC80MpnJkitlJju8sSDWsr0Bb4dPceo=
269269
github.com/livekit/mediatransportutil v0.0.0-20250922175932-f537f0880397/go.mod h1:mSNtYzSf6iY9xM3UX42VEI+STHvMgHmrYzEHPcdhB8A=
270-
github.com/livekit/protocol v1.43.1-0.20251112192040-8bdcb749c402 h1:mMIddIE1wlvgwIDYZ48M4eptU4dzA2DqzWzeT7OTkcY=
271-
github.com/livekit/protocol v1.43.1-0.20251112192040-8bdcb749c402/go.mod h1:TpqU2qCI1ES4Lk7PAWSgYO4RaexfVXb54ZO2hXv0Bmc=
272-
github.com/livekit/psrpc v0.7.1-0.20251105165826-1016ad610a7e h1:K6GKMFGJW8U2RoEyi8Zar7pPwUB7RMsn3AEJXf/Mgfc=
273-
github.com/livekit/psrpc v0.7.1-0.20251105165826-1016ad610a7e/go.mod h1:bZ4iHFQptTkbPnB0LasvRNu/OBYXEu1NA6O5BMFo9kk=
270+
github.com/livekit/protocol v1.43.3-0.20251127030154-5d65f30ee664 h1:CfKrVfzkGDvN9XeKqjt/Ap4sEbeUiLGSo3hgMikBDXg=
271+
github.com/livekit/protocol v1.43.3-0.20251127030154-5d65f30ee664/go.mod h1:yjkL2/HcaCRyHykP9rLgKST2099AGd8laaU8EuHMnfw=
272+
github.com/livekit/psrpc v0.7.1 h1:ms37az0QTD3UXIWuUC5D/SkmKOlRMVRsI261eBWu/Vw=
273+
github.com/livekit/psrpc v0.7.1/go.mod h1:bZ4iHFQptTkbPnB0LasvRNu/OBYXEu1NA6O5BMFo9kk=
274274
github.com/livekit/server-sdk-go/v2 v2.12.9-0.20251112193538-ed23dded48f9 h1:NjL66OFpkQJMhdvi0WCGWaPUr6XE1JGQwyKpNXWj4hg=
275275
github.com/livekit/server-sdk-go/v2 v2.12.9-0.20251112193538-ed23dded48f9/go.mod h1:YGjcmx4bSoEWGFqd1nqfVw8a+KQuOHXpr/prKtWRZaQ=
276276
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=

0 commit comments

Comments
 (0)