fix(send): resolve Brazilian 9th digit by asking WhatsApp for both variants
Accounts created before the 9th digit rollout are still registered without it (554291389691), newer ones with it (5542991389691). The DDD-based rewrite in CreateJID cannot be right for every account, and the existence check queried only the number as received, so sends to 5542991389691 failed for an account registered as 554291389691. validateAndCheckUserExists now queries both forms in one IsOnWhatsApp call and uses the registered one (received form first). Non-Brazilian numbers, groups, LIDs and landlines follow the previous path unchanged. Related: upstream issue #214 / PR #208. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
03d619bb55
commit
5b71495e93
4 files changed
+123
No files matched your search
@@ -384,3 +384,34 @@ func TestCanonicalJID(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBRPhoneVariants(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want []string
|
||||
}{
|
||||
{"13 digits with 9", "5542991389691", []string{"5542991389691", "554291389691"}},
|
||||
{"12 digits without 9", "554291389691", []string{"554291389691", "5542991389691"}},
|
||||
{"plus and JID suffix", "[email protected]", []string{"5511987654321", "551187654321"}},
|
||||
{"formatted", "+55 (42) 99138-9691", []string{"5542991389691", "554291389691"}},
|
||||
{"landline", "554232221234", nil},
|
||||
{"not Brazil", "15551234567", nil},
|
||||
{"group", "[email protected]", nil},
|
||||
{"lid", "255284433936406@lid", nil},
|
||||
{"13 digits without 9 after DDD", "5542891389691", nil},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := BRPhoneVariants(tt.input)
|
||||
if len(got) != len(tt.want) {
|
||||
t.Fatalf("BRPhoneVariants(%q) = %v, want %v", tt.input, got, tt.want)
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != tt.want[i] {
|
||||
t.Fatalf("BRPhoneVariants(%q) = %v, want %v", tt.input, got, tt.want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user