-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_accounts.go
More file actions
85 lines (69 loc) · 1.76 KB
/
cmd_accounts.go
File metadata and controls
85 lines (69 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"net/url"
"github.com/spf13/cobra"
)
func accountsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "accounts",
Short: "Manage connected chat accounts",
}
cmd.AddCommand(accountsListCmd())
cmd.AddCommand(accountsContactsCmd())
return cmd
}
func accountsListCmd() *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "List all connected messaging accounts",
Long: `List all connected messaging accounts.
Shows accounts from all networks (WhatsApp, Telegram, iMessage, etc.)
actively connected to Beeper Desktop.
Examples:
beeper accounts list`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := getClient()
if err != nil {
return err
}
result, err := client.request("GET", "/v1/accounts", nil, nil)
if err != nil {
return err
}
outputResult(result)
return nil
},
}
}
func accountsContactsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "contacts",
Short: "Manage contacts on accounts",
}
cmd.AddCommand(contactsSearchCmd())
return cmd
}
func contactsSearchCmd() *cobra.Command {
return &cobra.Command{
Use: "search <account-id> <query>",
Short: "Search contacts on a specific account",
Long: `Search contacts on a specific account.
Uses the network's search API to find contacts.
Examples:
beeper accounts contacts search "whatsapp:123456" "John"`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := getClient()
if err != nil {
return err
}
params := map[string]interface{}{"query": args[1]}
result, err := client.request("GET", "/v1/accounts/"+url.PathEscape(cleanID(args[0]))+"/contacts", params, nil)
if err != nil {
return err
}
outputResult(result)
return nil
},
}
}