Skip to content

feat(user): add endpoint to resolve phone number from LID - #179

Open
fmedeiros95 wants to merge 1 commit into
evolution-foundation:mainfrom
fmedeiros95:feat/resolve-lid-phone-number
Open

feat(user): add endpoint to resolve phone number from LID#179
fmedeiros95 wants to merge 1 commit into
evolution-foundation:mainfrom
fmedeiros95:feat/resolve-lid-phone-number

Conversation

@fmedeiros95

@fmedeiros95 fmedeiros95 commented Aug 20, 2026

Copy link
Copy Markdown

Summary

  • Adds POST /user/lid to resolve a LID (xxxx@lid) back to its phone number, reading whatsmeow's local LID store (client.Store.LIDs.GetPNForLID).
  • The WhatsApp protocol only supports server-side resolution in the PN -> LID direction; LID -> PN mappings are only known once received passively (message, group sync, etc). As a best-effort fallback, an optional groupJid in the request body triggers a fresh GetGroupInfo on that group (participant lists include phone numbers for LID participants), then retries the lookup before giving up.

Request/response

POST /user/lid
{ "lid": "123456789012345@lid", "groupJid": "120363012345678901@g.us" }

200 { "message": "success", "data": { "lid": "...@lid", "phoneNumber": "...", "jid": "...@s.whatsapp.net" } }

Test plan

  • go build ./pkg/user/... passes
  • Manual test against a live instance with a known LID/group pair

Summary by Sourcery

Expose phone-number resolution for WhatsApp LIDs through the user API.

New Features:

  • Add a user endpoint that resolves a WhatsApp LID to its corresponding phone number and JID.
  • Support an optional group lookup fallback when the LID mapping is not cached locally.

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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @fmedeiros95, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 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 flow

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Introduce POST /user/lid API endpoint and wire it into the routing and handler layers.
  • Register /user/lid route under the /user group with JID validation middleware for lid and groupJid fields.
  • Extend the UserHandler interface with a ResolveLid method and implement the HTTP handler function.
  • Add request binding, required lid validation, instance retrieval, and response marshalling in the new handler.
pkg/routes/routes.go
pkg/user/handler/user_handler.go
Add service-layer support for resolving a LID to phone number and JID using the whatsmeow client and optional group refresh.
  • Extend UserService interface with ResolveLid and define ResolveLidStruct and ResolveLidResult DTOs for request/response payloads.
  • Validate lid and groupJid JIDs and servers using utils.ParseJID and appropriate WhatsApp server constants.
  • Use ensureClientConnected to obtain a client, then client.Store.LIDs.GetPNForLID to resolve the phone number from the LID.
  • Implement best-effort fallback by calling client.GetGroupInfo when groupJid is provided and the initial lookup yields an empty phone number, then retrying the LID lookup.
  • Return structured error messages for invalid inputs, missing LID store, or absent phone number mappings, and construct the final response containing lid, phoneNumber, and jid.
pkg/user/service/user_service.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant