fix(send): send to known LIDs passed as phone numbers; expose version
Integrations that store the contact's LID as its number (255284433936406) failed with 'no LID found for [email protected]'. When the number is not a registered phone and the instance's LID store maps it to a phone number, send to <number>@lid instead. GET /server/ok now also returns the running version, so a deployment can be checked without reading the startup log. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c9511a636e
commit
b140fdb390
6 files changed
+91
-4
No files matched your search
@@ -230,6 +230,28 @@ func BRPhoneVariants(number string) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LIDCandidate returns the user part of number when it could be a LID sent as
|
||||
// a phone number ("255284433936406", "[email protected]"), or ""
|
||||
// when it has another server, a device suffix or non-digit characters.
|
||||
func LIDCandidate(number string) string {
|
||||
if strings.Contains(number, "@") {
|
||||
if !strings.HasSuffix(number, "@"+whatsmeow_types.DefaultUserServer) {
|
||||
return ""
|
||||
}
|
||||
number = strings.Split(number, "@")[0]
|
||||
}
|
||||
number = strings.TrimPrefix(strings.TrimSpace(number), "+")
|
||||
if len(number) < 8 {
|
||||
return ""
|
||||
}
|
||||
for _, r := range number {
|
||||
if r < '0' || r > '9' {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return number
|
||||
}
|
||||
|
||||
// ParseJID parses a number string into a WhatsApp JID with validation
|
||||
func ParseJID(arg string) (whatsmeow_types.JID, bool) {
|
||||
if arg == "" {
|
||||
|
||||
@@ -415,3 +415,23 @@ func TestBRPhoneVariants(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLIDCandidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{"255284433936406", "255284433936406"},
|
||||
{"[email protected]", "255284433936406"},
|
||||
{"255284433936406@lid", ""},
|
||||
{"[email protected]", ""},
|
||||
{"255284433936406:[email protected]", ""},
|
||||
{"+55 (42) 99138-9691", ""},
|
||||
{"1234", ""},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := LIDCandidate(tt.input); got != tt.want {
|
||||
t.Errorf("LIDCandidate(%q) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user