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
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user