GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.
Go botgogolanggolang-whatsappgolang-whatsapp-apirestrest-apiwhatsappwhatsapp-apiwhatsapp-api-gowhatsapp-multi-devicewhatsapp-web-multi-device
feat: Add support for LID (Linked ID) resolution in user account handling
Aldino Kemal17ff32fe82a6
diff --git a/src/config/settings.go b/src/config/settings.goindex d29ee200..257edfae 100644--- a/src/config/settings.go+++ b/src/config/settings.go@@ -41,6 +41,7 @@ var (WhatsappSettingMaxDownloadSize int64 = 500000000 // 500MBWhatsappTypeUser = "@s.whatsapp.net"WhatsappTypeGroup = "@g.us"+ WhatsappTypeLid = "@lid"WhatsappAccountValidation = trueChatStorageURI = "file:storages/chatstorage.db"diff --git a/src/domains/user/account.go b/src/domains/user/account.goindex 6bba4f4e..dbf16e2d 100644--- a/src/domains/user/account.go+++ b/src/domains/user/account.go@@ -26,7 +26,9 @@ type InfoResponseData struct {}type InfoResponse struct {- Data []InfoResponseData `json:"data"`+ Data []InfoResponseData `json:"data"`+ ResolvedPhone string `json:"resolved_phone,omitempty"`+ ResolvedLID string `json:"resolved_lid,omitempty"`}type AvatarRequest struct {diff --git a/src/pkg/utils/whatsapp.go b/src/pkg/utils/whatsapp.goindex 751b0cbf..95a9ac5e 100644--- a/src/pkg/utils/whatsapp.go+++ b/src/pkg/utils/whatsapp.go@@ -655,11 +655,26 @@ func IsOnWhatsapp(client *whatsmeow.Client, jid string) bool {func ValidateJidWithLogin(client *whatsmeow.Client, jid string) (types.JID, error) {MustLogin(client)+ parsedJID, err := ParseJID(jid)+ if err != nil {+ return types.JID{}, err+ }++ // If it's an @lid JID, try to resolve to phone number+ if parsedJID.Server == "lid" {+ resolved := ResolveLIDToPhone(context.Background(), parsedJID, client)+ if resolved.Server != "lid" {+ parsedJID = resolved // Use resolved phone-based JID+ }+ // Skip IsOnWhatsapp check for LIDs+ return parsedJID, nil+ }+if config.WhatsappAccountValidation && !IsOnWhatsapp(client, jid) {return types.JID{}, pkgError.InvalidJID(fmt.Sprintf("Phone %s is not on whatsapp", jid))}- return ParseJID(jid)+ return parsedJID, nil}// MustLogin ensures the WhatsApp client is logged in@@ -674,6 +689,67 @@ func MustLogin(client *whatsmeow.Client) {}}+// ResolveLIDToPhone converts @lid JIDs to their corresponding @s.whatsapp.net JIDs+// Returns the original JID if it's not an @lid or if LID lookup fails+func ResolveLIDToPhone(ctx context.Context, jid types.JID, client *whatsmeow.Client) types.JID {+ // Only process @lid JIDs+ if jid.Server != "lid" {+ return jid+ }++ // Safety check+ if client == nil || client.Store == nil || client.Store.LIDs == nil {+ logrus.Warnf("Cannot resolve LID %s: client not available", jid.String())+ return jid+ }++ // Attempt to get the phone number for this LID+ pn, err := client.Store.LIDs.GetPNForLID(ctx, jid)+ if err != nil {+ logrus.Debugf("Failed to resolve LID %s to phone number: %v", jid.String(), err)+ return jid+ }++ // If we got a valid phone number, use it+ if !pn.IsEmpty() {+ logrus.Debugf("Resolved LID %s to phone number %s", jid.String(), pn.String())+ return pn+ }++ // Fallback to original JID+ return jid+}++// ResolvePhoneToLID converts @s.whatsapp.net JIDs to their corresponding @lid JIDs+// Returns empty JID if it's not a user JID or if LID lookup fails+func ResolvePhoneToLID(ctx context.Context, jid types.JID, client *whatsmeow.Client) types.JID {+ // Only process user JIDs+ if jid.Server != types.DefaultUserServer {+ return types.JID{}+ }++ // Safety check+ if client == nil || client.Store == nil || client.Store.LIDs == nil {+ logrus.Debugf("Cannot resolve phone %s to LID: client not available", jid.String())+ return types.JID{}+ }++ // Attempt to get the LID for this phone number+ lid, err := client.Store.LIDs.GetLIDForPN(ctx, jid)+ if err != nil {+ logrus.Debugf("Failed to resolve phone %s to LID: %v", jid.String(), err)+ return types.JID{}+ }++ // If we got a valid LID, return it+ if !lid.IsEmpty() {+ logrus.Debugf("Resolved phone %s to LID %s", jid.String(), lid.String())+ return lid+ }++ return types.JID{}+}+// Internal message types for event handlingtype EvtMessage struct {Text string `json:"text"`diff --git a/src/ui/rest/user.go b/src/ui/rest/user.goindex 27b9f200..3b3b4e2d 100644--- a/src/ui/rest/user.go+++ b/src/ui/rest/user.go@@ -43,7 +43,7 @@ func (controller *User) UserInfo(c *fiber.Ctx) error {Status: 200,Code: "SUCCESS",Message: "Success get user info",- Results: response.Data[0],+ Results: response,})}diff --git a/src/usecase/user.go b/src/usecase/user.goindex dd235a23..37868022 100644--- a/src/usecase/user.go+++ b/src/usecase/user.go@@ -44,6 +44,23 @@ func (service serviceUser) Info(ctx context.Context, request domainUser.InfoRequreturn response, err}+ // Parse original input to check if it was a LID+ originalJID, _ := utils.ParseJID(request.Phone)+ wasLID := originalJID.Server == "lid"++ // If input was LID and resolved to phone, include resolved phone+ if wasLID && dataWaRecipient.Server == types.DefaultUserServer {+ response.ResolvedPhone = dataWaRecipient.User+ }++ // If input was phone number, try to get corresponding LID+ if dataWaRecipient.Server == types.DefaultUserServer {+ lid := utils.ResolvePhoneToLID(ctx, dataWaRecipient, client)+ if !lid.IsEmpty() {+ response.ResolvedLID = lid.String()+ }+ }+jids = append(jids, dataWaRecipient)resp, err := client.GetUserInfo(ctx, jids)if err != nil {diff --git a/src/views/components/AccountUserInfo.js b/src/views/components/AccountUserInfo.jsindex baa7a3e5..23f1510e 100644--- a/src/views/components/AccountUserInfo.js+++ b/src/views/components/AccountUserInfo.js@@ -13,6 +13,8 @@ export default {name: null,status: null,devices: [],+ resolvedPhone: null,+ resolvedLid: null,//loading: false,}@@ -51,9 +53,17 @@ export default {this.loading = true;try {let response = await window.http.get(`/user/info?phone=${this.phone_id}`)- this.name = response.data.results.verified_name;- this.status = response.data.results.status;- this.devices = response.data.results.devices;+ const results = response.data.results;+ const userData = results.data && results.data.length > 0 ? results.data[0] : null;++ if (userData) {+ this.name = userData.verified_name;+ this.status = userData.status;+ this.devices = userData.devices || [];+ }++ this.resolvedPhone = results.resolved_phone || null;+ this.resolvedLid = results.resolved_lid || null;} catch (error) {if (error.response) {throw new Error(error.response.data.message);@@ -68,6 +78,8 @@ export default {this.name = null;this.status = null;this.devices = [];+ this.resolvedPhone = null;+ this.resolvedLid = null;this.type = window.TYPEUSER;}},@@ -77,12 +89,12 @@ export default {<a class="ui olive right ribbon label">Account</a><div class="header">User Info</div><div class="description">- You can search someone user info by phone+ You can search someone user info by phone or LID</div></div></div>--++<!-- Modal UserInfo --><div class="ui small modal" id="modalUserInfo"><i class="close icon"></i>@@ -99,18 +111,49 @@ export default {</button></form>- <div v-if="devices.length > 0" class="center">- <ol>- <li>Name: {{ name }}</li>- <li>Status: {{ status }}</li>- <li>Device:- <ul>- <li v-for="d in devices">- {{ d.Device }}- </li>- </ul>- </li>- </ol>+ <div v-if="devices.length > 0 || resolvedPhone || resolvedLid" class="ui segment" style="margin-top: 1em;">+ <div class="ui list">+ <div class="item" v-if="resolvedPhone">+ <i class="phone icon"></i>+ <div class="content">+ <div class="header">Resolved Phone</div>+ <div class="description">{{ resolvedPhone }}</div>+ </div>+ </div>+ <div class="item" v-if="resolvedLid">+ <i class="linkify icon"></i>+ <div class="content">+ <div class="header">Resolved LID</div>+ <div class="description">{{ resolvedLid }}</div>+ </div>+ </div>+ <div class="item" v-if="name">+ <i class="user icon"></i>+ <div class="content">+ <div class="header">Name</div>+ <div class="description">{{ name }}</div>+ </div>+ </div>+ <div class="item" v-if="status">+ <i class="info circle icon"></i>+ <div class="content">+ <div class="header">Status</div>+ <div class="description">{{ status }}</div>+ </div>+ </div>+ <div class="item" v-if="devices.length > 0">+ <i class="mobile alternate icon"></i>+ <div class="content">+ <div class="header">Devices ({{ devices.length }})</div>+ <div class="ui relaxed list">+ <div class="item" v-for="d in devices" :key="d.AD">+ <i class="tablet icon"></i>+ <div class="content">{{ d.Device }} - {{ d.AD }}</div>+ </div>+ </div>+ </div>+ </div>+ </div></div></div></div>diff --git a/src/views/components/generic/FormRecipient.js b/src/views/components/generic/FormRecipient.jsindex e937de71..6dfdab5a 100644--- a/src/views/components/generic/FormRecipient.js+++ b/src/views/components/generic/FormRecipient.js@@ -40,6 +40,7 @@ export default {{ value: window.TYPEUSER, text: 'Private Message' },{ value: window.TYPEGROUP, text: 'Group Message' },{ value: window.TYPENEWSLETTER, text: 'Newsletter' },+ { value: window.TYPELID, text: 'LID (Linked ID)' },{ value: window.TYPESTATUS, text: 'Status' }];},diff --git a/src/views/index.html b/src/views/index.htmlindex d3f92f93..7cbeed6f 100644--- a/src/views/index.html+++ b/src/views/index.html@@ -169,6 +169,7 @@window.TYPEGROUP = "@g.us";window.TYPEUSER = "@s.whatsapp.net";window.TYPENEWSLETTER = "@newsletter";+ window.TYPELID = "@lid";window.TYPESTATUS = "status@broadcast";window.showErrorInfo = (message) => {$('body').toast({