Skip to content

Feature: Get Group Info from Invite Link#8

Open
moothz wants to merge 2 commits intoEvolutionAPI:mainfrom
moothz:feature/get-invite-info
Open

Feature: Get Group Info from Invite Link#8
moothz wants to merge 2 commits intoEvolutionAPI:mainfrom
moothz:feature/get-invite-info

Conversation

@moothz
Copy link
Copy Markdown

@moothz moothz commented Apr 4, 2026

Adds a new endpoint to retrieve detailed group information directly from a WhatsApp invite link without requiring the account to join the group first. Returns name, description, owner JID, and creation timestamp.
This is the same functionality as clicking an invite link to preview the group (view name, photo, members, if contacts are in the group, etc.)
These changes have been in effect in my codebase since december (early acess) - throughly tested.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement

Testing

  • Manual testing completed
  • Functionality verified in development environment
  • No breaking changes introduced

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have tested my changes thoroughly
  • Any dependent changes have been merged and published

Summary by Sourcery

Add an endpoint to retrieve WhatsApp group details from an invite link and document its usage alongside existing group APIs.

New Features:

  • Expose POST /group/invite-info endpoint to fetch group information directly from an invite link without joining the group.

Enhancements:

  • Extend group service and handler interfaces to support fetching group info from invite links and wire the new route into the HTTP router.

Documentation:

  • Document the new /group/invite-info endpoint in the groups API guide, including request/response examples and cURL usage.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 4, 2026

Reviewer's Guide

Adds a new /group/invite-info endpoint to fetch WhatsApp group metadata from an invite link (or code) without joining, wires it through the HTTP handler and service layer, and documents it in the API guides.

Sequence diagram for the new /group/invite-info endpoint

sequenceDiagram
    actor ApiClient
    participant GinRouter
    participant GroupHandler
    participant GroupService
    participant LoggerWrapper
    participant WhatsAppClient

    ApiClient->>GinRouter: POST /group/invite-info { code }
    GinRouter->>GroupHandler: GetGroupInfoFromInviteLink(ctx)
    GroupHandler->>GroupHandler: ctx.MustGet(instance)
    GroupHandler-->>ApiClient: 500 error (instance not found)
    note over GroupHandler,ApiClient: Alternative path if instance is missing
    GroupHandler->>GroupHandler: ctx.ShouldBindBodyWithJSON(data)
    GroupHandler-->>ApiClient: 400 error (invalid body)
    note over GroupHandler,ApiClient: Alternative path if body binding fails
    GroupHandler->>GroupHandler: validate data.Code not empty
    GroupHandler-->>ApiClient: 400 error (code is required)
    note over GroupHandler,ApiClient: Alternative path if code is empty

    GroupHandler->>GroupService: GetGroupInfoFromInviteLink(data, instance)
    GroupService->>GroupService: ensureClientConnected(instance.Id)
    GroupService-->>ApiClient: 500 error (client connection error)
    note over GroupService,ApiClient: Alternative path if client not connected

    GroupService->>GroupService: normalize code (strip chat.whatsapp.com/)
    GroupService->>WhatsAppClient: GetGroupInfoFromLink(code)
    WhatsAppClient-->>GroupService: GroupInfo or error
    GroupService->>LoggerWrapper: LogError on failure
    GroupService-->>GroupHandler: GroupInfo or error

    GroupHandler-->>ApiClient: 500 error (internal)
    note over GroupHandler,ApiClient: Alternative path if service returns error
    GroupHandler-->>ApiClient: 200 { message: success, data: GroupInfo }
Loading

Updated class diagram for group handler and service with invite-info support

classDiagram
    class GroupHandler {
        <<interface>>
        ListGroups(ctx)
        GetGroupInfo(ctx)
        GetGroupInviteLink(ctx)
        GetGroupInfoFromInviteLink(ctx)
        SetGroupPhoto(ctx)
        SetGroupName(ctx)
        SetGroupDescription(ctx)
    }

    class groupHandler {
        +groupService GroupService
        +GetGroupInfoFromInviteLink(ctx)
    }

    class GroupService {
        <<interface>>
        ListGroups(instance)
        GetGroupInfo(data, instance)
        GetGroupInviteLink(data, instance)
        GetGroupInfoFromInviteLink(data, instance)
        SetGroupPhoto(data, instance)
        SetGroupName(data, instance)
        SetGroupDescription(data, instance)
    }

    class groupService {
        +loggerWrapper LoggerWrapper
        +ensureClientConnected(instanceId)
        +GetGroupInviteLink(data, instance) string
        +GetGroupInfoFromInviteLink(data, instance) GroupInfo
    }

    class GetGroupInfoFromInviteLinkStruct {
        +Code string
    }

    class Instance {
        +Id string
    }

    class LoggerWrapper {
        +GetLogger(instanceId) Logger
    }

    class Logger {
        +LogError(format, values)
    }

    class WhatsAppClient {
        +GetGroupInfoFromLink(ctx, code) GroupInfo
    }

    class GroupInfo {
        +JID string
        +OwnerJID string
        +GroupName GroupNameInfo
        +GroupCreated time
    }

    class GroupNameInfo {
        +Name string
        +NameSetAt time
        +NameSetBy string
    }

    GroupHandler <|.. groupHandler
    GroupService <|.. groupService
    groupHandler --> GroupService
    groupService --> LoggerWrapper
    LoggerWrapper --> Logger
    groupService --> Instance
    groupService --> WhatsAppClient
    groupService --> GetGroupInfoFromInviteLinkStruct
    groupService --> GroupInfo
    GroupInfo --> GroupNameInfo
Loading

File-Level Changes

Change Details Files
Introduce HTTP endpoint /group/invite-info to return group information from an invite link or code without requiring group membership.
  • Extend GroupHandler interface with GetGroupInfoFromInviteLink method and implement it in group_handler
  • Bind and validate request body into GetGroupInfoFromInviteLinkStruct, ensuring code field is present
  • Resolve instance from Gin context, call groupService.GetGroupInfoFromInviteLink, and return standardized JSON success/error responses
  • Register POST /group/invite-info route under /group in routes.go without JID validation middleware
pkg/group/handler/group_handler.go
pkg/routes/routes.go
Extend group service layer to support retrieving group information via invite links and expose appropriate request struct.
  • Extend GroupService interface with GetGroupInfoFromInviteLink method returning *types.GroupInfo
  • Add GetGroupInfoFromInviteLinkStruct DTO with json:"code"
  • Implement GetGroupInfoFromInviteLink to ensure client connection, normalize full invite URLs to bare codes, call client.GetGroupInfoFromLink, log errors with instance-scoped logger, and return the resulting GroupInfo
pkg/group/service/group_service.go
Document the new invite-info endpoint in the API groups documentation, including request, response, and example usage.
  • Add navigation entry and new section "Informações via Link de Convite" describing POST /group/invite-info
  • Specify request body schema with code field accepting full URL or code and detail success response schema including JID, OwnerJID, GroupName, and GroupCreated
  • Provide example cURL invocation and keep existing "Link de Convite" section after the new section
docs/wiki/guias-api/api-groups.md

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 security issue, and left some high level feedback:

Security issues:

  • Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource. (link)

General comments:

  • In GetGroupInfoFromInviteLink, you're declaring var data *group_service.GetGroupInfoFromInviteLinkStruct and then calling ShouldBindBodyWithJSON(&data), which results in a pointer to a nil pointer; switch this to a non-pointer struct (e.g., var data group_service.GetGroupInfoFromInviteLinkStruct and bind with &data) to avoid unexpected nil dereferences and to match how other handlers bind request bodies.
  • The logic that extracts the invite code (strings.Contains + strings.Split on chat.whatsapp.com/) is brittle for variant URLs; consider using net/url parsing to robustly handle different URL formats, query parameters, trailing slashes, and potential whitespace around the code.
  • In api-groups.md, right after the /group/info cURL example there is a stray }' line left in the document, which should be removed to keep the markdown and JSON examples well-formed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `GetGroupInfoFromInviteLink`, you're declaring `var data *group_service.GetGroupInfoFromInviteLinkStruct` and then calling `ShouldBindBodyWithJSON(&data)`, which results in a pointer to a nil pointer; switch this to a non-pointer struct (e.g., `var data group_service.GetGroupInfoFromInviteLinkStruct` and bind with `&data`) to avoid unexpected nil dereferences and to match how other handlers bind request bodies.
- The logic that extracts the invite code (`strings.Contains` + `strings.Split` on `chat.whatsapp.com/`) is brittle for variant URLs; consider using `net/url` parsing to robustly handle different URL formats, query parameters, trailing slashes, and potential whitespace around the code.
- In `api-groups.md`, right after the `/group/info` cURL example there is a stray `}'` line left in the document, which should be removed to keep the markdown and JSON examples well-formed.

## Individual Comments

### Comment 1
<location path="docs/wiki/guias-api/api-groups.md" line_range="187-189" />
<code_context>
SUA-CHAVE-API
</code_context>
<issue_to_address>
**security (curl-auth-header):** Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.

*Source: gitleaks*
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +187 to +189
curl -X POST http://localhost:4000/group/invite-info \
-H "Content-Type: application/json" \
-H "apikey: SUA-CHAVE-API" \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security (curl-auth-header): Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.

Source: gitleaks

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