feat(user): add endpoint to resolve phone number from LID - #179
Open
fmedeiros95 wants to merge 1 commit into
Open
feat(user): add endpoint to resolve phone number from LID#179fmedeiros95 wants to merge 1 commit into
fmedeiros95 wants to merge 1 commit into
Conversation
Adds POST /user/lid, reading whatsmeow's local LID store (client.Store.LIDs.GetPNForLID) to resolve a LID (xxxx@lid) back to its phone number. The WhatsApp protocol has no server query for this direction (only PN->LID is supported), so the mapping is only available once received passively. As a best-effort fallback, an optional groupJid triggers a fresh GetGroupInfo on that group, which returns phone numbers for LID participants and populates the store before retrying the lookup.
There was a problem hiding this comment.
Sorry @fmedeiros95, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Reviewer's GuideAdds a new /user/lid POST endpoint that resolves a WhatsApp LID to its underlying phone number and JID using whatsmeow’s local LID store, with an optional group-based fallback refresh when the mapping is missing. Sequence diagram for POST /user/lid LID resolution flowsequenceDiagram
actor ApiClient
participant GinRouter
participant JidValidationMiddleware
participant UserHandler
participant UserService
participant WhatsmeowClient
participant LIDStore
ApiClient->>GinRouter: POST /user/lid
GinRouter->>JidValidationMiddleware: ValidateJIDFields(lid, groupJid)
JidValidationMiddleware-->>GinRouter: ok / 400 on invalid JIDs
GinRouter->>UserHandler: ResolveLid(ctx)
UserHandler->>UserService: ResolveLid(ResolveLidStruct, Instance)
UserService->>WhatsmeowClient: ensureClientConnected(instance.Id)
WhatsmeowClient-->>UserService: client
UserService->>UserService: utils.ParseJID(data.Lid)
UserService->>LIDStore: GetPNForLID(ctx, lidJID)
LIDStore-->>UserService: pn
alt [pn.IsEmpty() and data.GroupJid != ""]
UserService->>UserService: utils.ParseJID(data.GroupJid)
UserService->>WhatsmeowClient: GetGroupInfo(ctx, groupJID)
WhatsmeowClient-->>UserService: group info
UserService->>LIDStore: GetPNForLID(ctx, lidJID)
LIDStore-->>UserService: pn (refreshed)
end
alt [pn.IsEmpty()]
UserService-->>UserHandler: error "no phone number mapping found for this lid"
UserHandler-->>ApiClient: 500 { error }
else [pn not empty]
UserService-->>UserHandler: ResolveLidResult{lid, phoneNumber, jid}
UserHandler-->>ApiClient: 200 { message: success, data }
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /user/lidto resolve a LID (xxxx@lid) back to its phone number, reading whatsmeow's local LID store (client.Store.LIDs.GetPNForLID).groupJidin the request body triggers a freshGetGroupInfoon that group (participant lists include phone numbers for LID participants), then retries the lookup before giving up.Request/response
Test plan
go build ./pkg/user/...passesSummary by Sourcery
Expose phone-number resolution for WhatsApp LIDs through the user API.
New Features: