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
@@ -26,6 +26,14 @@
|
||||
WhatsApp as duas variantes (com e sem o 9) e usam a que está registrada.
|
||||
Contas antigas sem o 9 (ex.: `554291389691`) passam a receber mesmo quando o
|
||||
sistema envia `5542991389691`, e vice-versa (upstream issue #214 / PR #208).
|
||||
- **LID enviado como número** — quando o `number` não existe como telefone mas
|
||||
é o LID de um contato já conhecido pela instância (ex.: `255284433936406`),
|
||||
o envio vai direto para `255284433936406@lid` em vez de falhar com
|
||||
`no LID found for [email protected]`.
|
||||
|
||||
### 🆕 Novidades
|
||||
- `GET /server/ok` passa a informar a versão em execução
|
||||
(`{"status":"ok","version":"0.7.2-evogo.3-<sha7>"}`).
|
||||
|
||||
### 🛡️ Estabilidade (correções da comunidade incorporadas pelo EvoGO)
|
||||
- **Crash `concurrent map writes`** — `clientPointer`, `myClientPointer` e
|
||||
|
||||
@@ -239,7 +239,7 @@ func setupRouter(db *gorm.DB, authDB *sql.DB, sqliteDB *sql.DB, config *config.C
|
||||
label_handler.NewLabelHandler(labelService),
|
||||
newsletter_handler.NewNewsletterHandler(newsletterService),
|
||||
pollHandler,
|
||||
server_handler.NewServerHandler(),
|
||||
server_handler.NewServerHandler(version),
|
||||
).AssignRoutes(r)
|
||||
|
||||
if config.ConnectOnStartup {
|
||||
|
||||
@@ -546,6 +546,15 @@ func (s *sendService) validateAndCheckUserExists(phone string, formatJid *bool,
|
||||
|
||||
// First attempt with formatJid=false
|
||||
remoteJID, found, err := s.checkSingleUserExists(client, phone, formatJidForCheck, instance.Id)
|
||||
if err != nil || !found {
|
||||
// Integrations often store the contact's LID as if it were a phone
|
||||
// number. If it is a LID this device already knows, send to it directly.
|
||||
if lid, ok := s.knownLID(client, phone, instance.Id); ok {
|
||||
s.loggerWrapper.GetLogger(instance.Id).LogInfo("[%s] Number %s is a known LID, sending to %s", instance.Id, phone, lid)
|
||||
formatJidFalse := false
|
||||
return validateMessageFields(lid.String(), &formatJidFalse, messageID, participant)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
s.loggerWrapper.GetLogger(instance.Id).LogWarn("[%s] Failed to check user existence: %v", instance.Id, err)
|
||||
// Continue with sending even if check fails (network issues, etc.)
|
||||
@@ -602,6 +611,32 @@ func (s *sendService) checkSingleUserExists(client *whatsmeow.Client, phone stri
|
||||
return remoteJID, true, nil
|
||||
}
|
||||
|
||||
// knownLID reports whether phone is actually a LID with a phone number mapping
|
||||
// in the local store, returning it as a @lid JID.
|
||||
func (s *sendService) knownLID(client *whatsmeow.Client, phone string, instanceId string) (types.JID, bool) {
|
||||
if client.Store == nil || client.Store.LIDs == nil {
|
||||
return types.JID{}, false
|
||||
}
|
||||
user := utils.LIDCandidate(phone)
|
||||
if user == "" {
|
||||
return types.JID{}, false
|
||||
}
|
||||
lid := types.NewJID(user, types.HiddenUserServer)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
pn, err := client.Store.LIDs.GetPNForLID(ctx, lid)
|
||||
if err != nil {
|
||||
s.loggerWrapper.GetLogger(instanceId).LogWarn("[%s] Failed to look up LID %s: %v", instanceId, lid, err)
|
||||
return types.JID{}, false
|
||||
}
|
||||
if pn.IsEmpty() {
|
||||
return types.JID{}, false
|
||||
}
|
||||
return lid, true
|
||||
}
|
||||
|
||||
// checkBRPhoneVariants queries every variant in a single IsOnWhatsApp call and
|
||||
// returns the JID of the first one that is registered, in the given order.
|
||||
// Errors are logged and reported as not found so the regular check still runs.
|
||||
|
||||
@@ -7,15 +7,17 @@ type ServerHandler interface {
|
||||
}
|
||||
|
||||
type serverHandler struct {
|
||||
version string
|
||||
}
|
||||
|
||||
// ServerOk implements ServerHandler.
|
||||
func (s *serverHandler) ServerOk(ctx *gin.Context) {
|
||||
ctx.JSON(200, gin.H{
|
||||
"status": "ok",
|
||||
"status": "ok",
|
||||
"version": s.version,
|
||||
})
|
||||
}
|
||||
|
||||
func NewServerHandler() ServerHandler {
|
||||
return &serverHandler{}
|
||||
func NewServerHandler(version string) ServerHandler {
|
||||
return &serverHandler{version: version}
|
||||
}
|
||||
@@ -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