Skip to content

Commit 44137fb

Browse files
gdbrnsDTS BBPSDMP Medanaldinokemal
authored
feat: Add Group Invite Link API endpoint (#384)
* feat: Add Group Invite Link API endpoint - Add GetGroupInviteLink method to group management interface - Implement business logic in usecase layer - Add validation for group invite link requests - Create REST API endpoint: GET /group/{group_id}/invite-link - Update OpenAPI documentation with new endpoint - Add .gitignore to exclude plan.md * fix: Update GetGroupInviteLinkResponse schema to match API consistency pattern * fix: Add default value and trailing newline to openapi.yaml * docs: Add Group Invite Link API to README documentation * fix: Add trailing newline to openapi.yaml to resolve YAML lint error * feat: Add Group Invite Link UI component and integration - Add GroupGetInviteLink.js Vue component with full functionality - Integrate component into index.html with proper imports and registration - Include auto-correction for group ID input - Add clipboard copy functionality for invite links - Implement proper loading states and error handling - Follow existing code patterns and architecture * feat: add /user/my/groups/metadata endpoint with enhanced group information - Add GroupMeta and MyGroupsMetadataResponse structs to domains/user - Extend IUserListing interface with MyGroupsMetadata method - Implement MyGroupsMetadata use-case with concurrency controls and context timeout - Add REST handler UserMyGroupsMetadata with 40s timeout - Create GroupMetaList.js Vue component with DataTable integration - Add green card UI following existing group component patterns - Wire component into index.html Group section - Update OpenAPI specification with new endpoint and response schema - Document endpoint in README API table Features: - Fetches group_id, name, is_admin status, admin_count, member_count - Includes invite_link for groups where user is admin - Bounded concurrency (8 goroutines) for safe WhatsApp API usage - Proper error handling and loading states in UI - Follows upstream Whatsmeow library design patterns * fix: remove unused ctxGroup variable causing build failure * Revert: Remove accidentally added metadata endpoint functionality - Remove /user/my/groups/metadata endpoint to prevent WhatsApp rate-limiting - Delete GroupMeta and MyGroupsMetadataResponse domain structs - Remove MyGroupsMetadata interface method and usecase implementation - Delete GroupMetaList.js frontend component and integration - Remove metadata endpoint route registration and handler - Update API documentation in README.md and OpenAPI spec * fix: update OpenAPI version and align documentation style - Update OpenAPI version from 6.9.0 to 6.10.0 - Fix /group/{group_id}/invite-link endpoint documentation style to match /group/info pattern - Change operationId to 'groupInviteLink' - Change summary to 'Group Invite Link' - Reorder path parameter fields (in: path first) - Remove example field from path parameter - Change copy button color to blue in GroupGetInviteLink component * refactor(api): change group invite link endpoint to use query parameters - Change API endpoint from /group/{group_id}/invite-link to /group/invite-link - Move group_id from path parameter to query parameter for consistency - Update GetGroupInviteLinkRequest struct tags from form to query - Modify REST handler to use QueryParser instead of path parameter extraction - Update OpenAPI documentation to reflect new endpoint structure - Adjust frontend component to send group_id as query parameter - Maintain existing validation logic compatibility Addresses PR #384 owner comments for API style consistency and OpenAPI documentation updates. Files changed: - src/domains/group/group.go - src/ui/rest/group.go - docs/openapi.yaml - src/views/components/GroupGetInviteLink.js Breaking change: API endpoint structure changed from path to query parameters * ✅ Fixed frontend response handling in GroupGetInviteLink.js - Added strict type checking to prevent assigning objects to string fields - Removed debug logs to follow master branch patterns - Added safe fallback when no valid string is found The component now safely handles API responses while maintaining consistency with existing codebase patterns. --------- Co-authored-by: DTS BBPSDMP Medan <bbpsdmpkemdan@gmail.com> Co-authored-by: Aldino Kemal <aldinokemal2104@gmail.com>
1 parent 4caf09b commit 44137fb

File tree

10 files changed

+372
-3
lines changed

10 files changed

+372
-3
lines changed

.gitignore

30 Bytes
Binary file not shown.

docs/openapi.yaml

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
openapi: "3.0.0"
22
info:
33
title: WhatsApp API MultiDevice
4-
version: 6.9.0
4+
version: 6.10.0
55
description: This API is used for sending whatsapp via API
66
servers:
77
- url: http://localhost:3000
@@ -312,6 +312,7 @@ paths:
312312
application/json:
313313
schema:
314314
$ref: '#/components/schemas/ErrorInternalServer'
315+
315316
/user/my/newsletters:
316317
get:
317318
operationId: userMyNewsletter
@@ -2212,6 +2213,45 @@ paths:
22122213
application/json:
22132214
schema:
22142215
$ref: '#/components/schemas/ErrorInternalServer'
2216+
/group/invite-link:
2217+
get:
2218+
operationId: groupInviteLink
2219+
tags:
2220+
- group
2221+
summary: Group Invite Link
2222+
parameters:
2223+
- name: group_id
2224+
in: query
2225+
schema:
2226+
type: string
2227+
required: true
2228+
description: WhatsApp Group ID
2229+
- name: reset
2230+
in: query
2231+
schema:
2232+
type: boolean
2233+
default: false
2234+
example: false
2235+
description: Reset existing invite link
2236+
responses:
2237+
'200':
2238+
description: OK
2239+
content:
2240+
application/json:
2241+
schema:
2242+
$ref: '#/components/schemas/GetGroupInviteLinkResponse'
2243+
'400':
2244+
description: Bad Request
2245+
content:
2246+
application/json:
2247+
schema:
2248+
$ref: '#/components/schemas/ErrorBadRequest'
2249+
'500':
2250+
description: Internal Server Error
2251+
content:
2252+
application/json:
2253+
schema:
2254+
$ref: '#/components/schemas/ErrorInternalServer'
22152255
/newsletter/unfollow:
22162256
post:
22172257
operationId: unfollowNewsletter
@@ -2419,6 +2459,8 @@ components:
24192459
type: boolean
24202460
Error:
24212461
type: number
2462+
2463+
24222464
UserInfoResponse:
24232465
type: object
24242466
required:
@@ -3256,4 +3298,24 @@ components:
32563298
results:
32573299
type: object
32583300
description: Group information object (structure may vary)
3259-
additionalProperties: true
3301+
additionalProperties: true
3302+
GetGroupInviteLinkResponse:
3303+
type: object
3304+
properties:
3305+
code:
3306+
type: string
3307+
example: SUCCESS
3308+
message:
3309+
type: string
3310+
example: Success get group invite link
3311+
results:
3312+
type: object
3313+
properties:
3314+
invite_link:
3315+
type: string
3316+
example: 'https://chat.whatsapp.com/ABC123...'
3317+
description: The group invite link
3318+
group_id:
3319+
type: string
3320+
example: '120363025982934543@g.us'
3321+
description: The group ID

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ You can fork or edit this source code !
352352
| ✅ | Set Group Locked | POST | /group/locked |
353353
| ✅ | Set Group Announce | POST | /group/announce |
354354
| ✅ | Set Group Topic | POST | /group/topic |
355+
| ✅ | Get Group Invite Link | GET | /group/:group_id/invite-link |
355356
| ✅ | Unfollow Newsletter | POST | /newsletter/unfollow |
356357
| ✅ | Get Chat List | GET | /chats |
357358
| ✅ | Get Chat Messages | GET | /chat/:chat_jid/messages |

src/domains/group/group.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ type GroupInfoRequest struct {
9999
GroupID string `json:"group_id" query:"group_id"`
100100
}
101101

102+
type GetGroupInviteLinkRequest struct {
103+
GroupID string `json:"group_id" query:"group_id"`
104+
Reset bool `json:"reset" query:"reset"`
105+
}
106+
107+
type GetGroupInviteLinkResponse struct {
108+
InviteLink string `json:"invite_link"`
109+
GroupID string `json:"group_id"`
110+
}
111+
102112
type GroupInfoResponse struct {
103113
Data any `json:"data"`
104114
}

src/domains/group/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type IGroupManagement interface {
1010
LeaveGroup(ctx context.Context, request LeaveGroupRequest) (err error)
1111
CreateGroup(ctx context.Context, request CreateGroupRequest) (groupID string, err error)
1212
GetGroupInfoFromLink(ctx context.Context, request GetGroupInfoFromLinkRequest) (response GetGroupInfoFromLinkResponse, err error)
13+
GetGroupInviteLink(ctx context.Context, request GetGroupInviteLinkRequest) (response GetGroupInviteLinkResponse, err error)
1314
GroupInfo(ctx context.Context, request GroupInfoRequest) (response GroupInfoResponse, err error)
1415
}
1516

src/ui/rest/group.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func InitRestGroup(app fiber.Router, service domainGroup.IGroupUsecase) Group {
3434
app.Post("/group/locked", rest.SetGroupLocked)
3535
app.Post("/group/announce", rest.SetGroupAnnounce)
3636
app.Post("/group/topic", rest.SetGroupTopic)
37+
app.Get("/group/invite-link", rest.GetGroupInviteLink)
3738
return rest
3839
}
3940

@@ -339,3 +340,21 @@ func (controller *Group) GroupInfo(c *fiber.Ctx) error {
339340
Results: response.Data,
340341
})
341342
}
343+
344+
func (controller *Group) GetGroupInviteLink(c *fiber.Ctx) error {
345+
var request domainGroup.GetGroupInviteLinkRequest
346+
err := c.QueryParser(&request)
347+
utils.PanicIfNeeded(err)
348+
349+
utils.SanitizePhone(&request.GroupID)
350+
351+
response, err := controller.Service.GetGroupInviteLink(c.UserContext(), request)
352+
utils.PanicIfNeeded(err)
353+
354+
return c.JSON(utils.ResponseData{
355+
Status: 200,
356+
Code: "SUCCESS",
357+
Message: "Success get group invite link",
358+
Results: response,
359+
})
360+
}

src/usecase/group.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,27 @@ func (service serviceGroup) GroupInfo(ctx context.Context, request domainGroup.G
339339

340340
return response, nil
341341
}
342+
343+
func (service serviceGroup) GetGroupInviteLink(ctx context.Context, request domainGroup.GetGroupInviteLinkRequest) (response domainGroup.GetGroupInviteLinkResponse, err error) {
344+
if err = validations.ValidateGetGroupInviteLink(ctx, request); err != nil {
345+
return response, err
346+
}
347+
utils.MustLogin(whatsapp.GetClient())
348+
349+
groupJID, err := utils.ValidateJidWithLogin(whatsapp.GetClient(), request.GroupID)
350+
if err != nil {
351+
return response, err
352+
}
353+
354+
inviteLink, err := whatsapp.GetClient().GetGroupInviteLink(groupJID, request.Reset)
355+
if err != nil {
356+
return response, err
357+
}
358+
359+
response = domainGroup.GetGroupInviteLinkResponse{
360+
InviteLink: inviteLink,
361+
GroupID: request.GroupID,
362+
}
363+
364+
return response, nil
365+
}

src/validations/group_validation.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,15 @@ func ValidateGroupInfo(ctx context.Context, request domainGroup.GroupInfoRequest
204204

205205
return nil
206206
}
207+
208+
func ValidateGetGroupInviteLink(ctx context.Context, request domainGroup.GetGroupInviteLinkRequest) error {
209+
err := validation.ValidateStructWithContext(ctx, &request,
210+
validation.Field(&request.GroupID, validation.Required),
211+
)
212+
213+
if err != nil {
214+
return pkgError.ValidationError(err.Error())
215+
}
216+
217+
return nil
218+
}

0 commit comments

Comments
 (0)