-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusername.go
More file actions
51 lines (44 loc) · 1.57 KB
/
Copy pathusername.go
File metadata and controls
51 lines (44 loc) · 1.57 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
package main
import (
"fmt"
"strings"
)
// This file implements `splashify username` — the CLI mirror of the app's
// /settings/username page. It manages the WhatsApp business username
// (vanity handle that appears in WhatsApp Search and on the business
// profile card).
//
// splashify username show current username + status
// splashify username suggestions list backend-suggested usernames
// splashify username adopt <name> claim a username (case-insensitive)
// splashify username delete release the current username
//
// Backed by /api/v1/app/phone/username[/suggestions]. The backend enforces
// Meta's vanity-name rules (length, characters, profanity); the CLI just
// forwards.
func cmdUsername(args []string) error {
sub := ""
if len(args) > 0 {
sub = args[0]
}
switch sub {
case "", "show", "get", "status":
return runReq("GET", "/app/phone/username", nil)
case "suggestions", "suggest", "ideas":
return runReq("GET", "/app/phone/username_suggestions", nil)
case "adopt", "claim", "set", "reserve":
if len(args) < 2 {
return fmt.Errorf("usage: splashify username adopt <name>")
}
name := strings.TrimSpace(args[1])
if name == "" {
return fmt.Errorf("username cannot be empty")
}
return runReq("POST", "/app/phone/username", map[string]any{"username": name})
case "delete", "release", "remove", "rm":
return runReq("DELETE", "/app/phone/username", nil)
default:
return fmt.Errorf("unknown username subcommand: %s\n"+
"run: splashify username (or suggestions | adopt <name> | delete)", sub)
}
}