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 Group Invite Link API endpoint (#384)
gdbrns44137fb859f1
diff --git a/.gitignore b/.gitignoreindex 89b5fa46..b7377173 100644Binary files a/.gitignore and b/.gitignore differdiff --git a/docs/openapi.yaml b/docs/openapi.yamlindex ebe85ee1..01fb8dca 100644--- a/docs/openapi.yaml+++ b/docs/openapi.yaml@@ -1,7 +1,7 @@openapi: "3.0.0"info:title: WhatsApp API MultiDevice- version: 6.9.0+ version: 6.10.0description: This API is used for sending whatsapp via APIservers:- url: http://localhost:3000@@ -312,6 +312,7 @@ paths:application/json:schema:$ref: '#/components/schemas/ErrorInternalServer'+/user/my/newsletters:get:operationId: userMyNewsletter@@ -2212,6 +2213,45 @@ paths:application/json:schema:$ref: '#/components/schemas/ErrorInternalServer'+ /group/invite-link:+ get:+ operationId: groupInviteLink+ tags:+ - group+ summary: Group Invite Link+ parameters:+ - name: group_id+ in: query+ schema:+ type: string+ required: true+ description: WhatsApp Group ID+ - name: reset+ in: query+ schema:+ type: boolean+ default: false+ example: false+ description: Reset existing invite link+ responses:+ '200':+ description: OK+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/GetGroupInviteLinkResponse'+ '400':+ description: Bad Request+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/ErrorBadRequest'+ '500':+ description: Internal Server Error+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/ErrorInternalServer'/newsletter/unfollow:post:operationId: unfollowNewsletter@@ -2419,6 +2459,8 @@ components:type: booleanError:type: number++UserInfoResponse:type: objectrequired:@@ -3256,4 +3298,24 @@ components:results:type: objectdescription: Group information object (structure may vary)- additionalProperties: true\ No newline at end of file+ additionalProperties: true+ GetGroupInviteLinkResponse:+ type: object+ properties:+ code:+ type: string+ example: SUCCESS+ message:+ type: string+ example: Success get group invite link+ results:+ type: object+ properties:+ invite_link:+ type: string+ example: 'https://chat.whatsapp.com/ABC123...'+ description: The group invite link+ group_id:+ type: string+ example: '[email protected]'+ description: The group IDdiff --git a/readme.md b/readme.mdindex 56238695..e4f783ca 100644--- a/readme.md+++ b/readme.md@@ -352,6 +352,7 @@ You can fork or edit this source code !| ✅ | Set Group Locked | POST | /group/locked || ✅ | Set Group Announce | POST | /group/announce || ✅ | Set Group Topic | POST | /group/topic |+| ✅ | Get Group Invite Link | GET | /group/:group_id/invite-link || ✅ | Unfollow Newsletter | POST | /newsletter/unfollow || ✅ | Get Chat List | GET | /chats || ✅ | Get Chat Messages | GET | /chat/:chat_jid/messages |diff --git a/src/domains/group/group.go b/src/domains/group/group.goindex 687c8cda..21e23a00 100644--- a/src/domains/group/group.go+++ b/src/domains/group/group.go@@ -99,6 +99,16 @@ type GroupInfoRequest struct {GroupID string `json:"group_id" query:"group_id"`}+type GetGroupInviteLinkRequest struct {+ GroupID string `json:"group_id" query:"group_id"`+ Reset bool `json:"reset" query:"reset"`+}++type GetGroupInviteLinkResponse struct {+ InviteLink string `json:"invite_link"`+ GroupID string `json:"group_id"`+}+type GroupInfoResponse struct {Data any `json:"data"`}diff --git a/src/domains/group/interfaces.go b/src/domains/group/interfaces.goindex eb362332..45c80224 100644--- a/src/domains/group/interfaces.go+++ b/src/domains/group/interfaces.go@@ -10,6 +10,7 @@ type IGroupManagement interface {LeaveGroup(ctx context.Context, request LeaveGroupRequest) (err error)CreateGroup(ctx context.Context, request CreateGroupRequest) (groupID string, err error)GetGroupInfoFromLink(ctx context.Context, request GetGroupInfoFromLinkRequest) (response GetGroupInfoFromLinkResponse, err error)+ GetGroupInviteLink(ctx context.Context, request GetGroupInviteLinkRequest) (response GetGroupInviteLinkResponse, err error)GroupInfo(ctx context.Context, request GroupInfoRequest) (response GroupInfoResponse, err error)}diff --git a/src/ui/rest/group.go b/src/ui/rest/group.goindex 4d940ccd..269522a0 100644--- a/src/ui/rest/group.go+++ b/src/ui/rest/group.go@@ -34,6 +34,7 @@ func InitRestGroup(app fiber.Router, service domainGroup.IGroupUsecase) Group {app.Post("/group/locked", rest.SetGroupLocked)app.Post("/group/announce", rest.SetGroupAnnounce)app.Post("/group/topic", rest.SetGroupTopic)+ app.Get("/group/invite-link", rest.GetGroupInviteLink)return rest}@@ -339,3 +340,21 @@ func (controller *Group) GroupInfo(c *fiber.Ctx) error {Results: response.Data,})}++func (controller *Group) GetGroupInviteLink(c *fiber.Ctx) error {+ var request domainGroup.GetGroupInviteLinkRequest+ err := c.QueryParser(&request)+ utils.PanicIfNeeded(err)++ utils.SanitizePhone(&request.GroupID)++ response, err := controller.Service.GetGroupInviteLink(c.UserContext(), request)+ utils.PanicIfNeeded(err)++ return c.JSON(utils.ResponseData{+ Status: 200,+ Code: "SUCCESS",+ Message: "Success get group invite link",+ Results: response,+ })+}diff --git a/src/usecase/group.go b/src/usecase/group.goindex da550689..edec9d1a 100644--- a/src/usecase/group.go+++ b/src/usecase/group.go@@ -339,3 +339,27 @@ func (service serviceGroup) GroupInfo(ctx context.Context, request domainGroup.Greturn response, nil}++func (service serviceGroup) GetGroupInviteLink(ctx context.Context, request domainGroup.GetGroupInviteLinkRequest) (response domainGroup.GetGroupInviteLinkResponse, err error) {+ if err = validations.ValidateGetGroupInviteLink(ctx, request); err != nil {+ return response, err+ }+ utils.MustLogin(whatsapp.GetClient())++ groupJID, err := utils.ValidateJidWithLogin(whatsapp.GetClient(), request.GroupID)+ if err != nil {+ return response, err+ }++ inviteLink, err := whatsapp.GetClient().GetGroupInviteLink(groupJID, request.Reset)+ if err != nil {+ return response, err+ }++ response = domainGroup.GetGroupInviteLinkResponse{+ InviteLink: inviteLink,+ GroupID: request.GroupID,+ }++ return response, nil+}diff --git a/src/validations/group_validation.go b/src/validations/group_validation.goindex ff7e4f8d..9a035610 100644--- a/src/validations/group_validation.go+++ b/src/validations/group_validation.go@@ -204,3 +204,15 @@ func ValidateGroupInfo(ctx context.Context, request domainGroup.GroupInfoRequestreturn nil}++func ValidateGetGroupInviteLink(ctx context.Context, request domainGroup.GetGroupInviteLinkRequest) error {+ err := validation.ValidateStructWithContext(ctx, &request,+ validation.Field(&request.GroupID, validation.Required),+ )++ if err != nil {+ return pkgError.ValidationError(err.Error())+ }++ return nil+}diff --git a/src/views/components/GroupGetInviteLink.js b/src/views/components/GroupGetInviteLink.jsnew file mode 100644index 00000000..074e5a76--- /dev/null+++ b/src/views/components/GroupGetInviteLink.js@@ -0,0 +1,238 @@+export default {+ name: 'GroupGetInviteLink',+ components: {},+ data() {+ return {+ group_id: '',+ inviteLink: '',+ resetLink: false,+ loading: false,+ copying: false,+ }+ },+ computed: {+ fullGroupID() {+ if (!this.group_id) return '';+ // Ensure suffix+ if (this.group_id.endsWith(window.TYPEGROUP)) {+ return this.group_id;+ }+ return this.group_id + window.TYPEGROUP;+ },+ isValidForm() {+ return this.group_id.trim() !== '';+ },+ displayGroupID() {+ if (!this.group_id) return '';+ // Show the full ID with suffix for clarity+ return this.fullGroupID;+ }+ },+ methods: {+ openModal() {+ this.reset();+ $('#modalGroupGetInviteLink').modal({+ onApprove: function () {+ return false;+ }+ }).modal('show');+ },+ async handleSubmit() {+ if (!this.isValidForm || this.loading) return;+ try {+ await this.getInviteLink();+ if (this.inviteLink) {+ showSuccessInfo('Group invite link fetched successfully!');+ } else {+ showErrorInfo('No invite link received from the server');+ }+ } catch (err) {+ showErrorInfo(err.message || err);+ }+ },+ async getInviteLink() {+ this.loading = true;+ try {+ const response = await window.http.get(`/group/invite-link`, {+ params: {+ group_id: this.fullGroupID,+ reset: this.resetLink+ }+ });+ if (response.data.results && typeof response.data.results.invite_link === 'string') {+ this.inviteLink = response.data.results.invite_link;+ } else if (response.data && typeof response.data.invite_link === 'string') {+ this.inviteLink = response.data.invite_link;+ } else if (typeof response.data.results === 'string') {+ this.inviteLink = response.data.results;+ } else if (typeof response.data === 'string') {+ this.inviteLink = response.data;+ } else {+ this.inviteLink = '';+ }+ } catch (error) {+ if (error.response) {+ throw new Error(error.response.data.message || error.response.data);+ }+ throw new Error(error.message);+ } finally {+ this.loading = false;+ }+ },+ reset() {+ this.group_id = '';+ this.inviteLink = '';+ this.resetLink = false;+ this.loading = false;+ this.copying = false;+ },+ async copyToClipboard() {+ if (this.inviteLink) {+ this.copying = true;+ try {+ // Try modern clipboard API first+ if (navigator.clipboard && navigator.clipboard.writeText) {+ await navigator.clipboard.writeText(this.inviteLink);+ showSuccessInfo('✅ Invite link copied to clipboard!');+ } else {+ // Fallback for older browsers+ this.fallbackCopyToClipboard();+ }+ } catch (err) {+ console.error('Clipboard API failed:', err);+ this.fallbackCopyToClipboard();+ } finally {+ this.copying = false;+ }+ } else {+ showErrorInfo('No invite link to copy');+ }+ },+ fallbackCopyToClipboard() {+ try {+ // Create a temporary input element+ const tempInput = document.createElement('input');+ tempInput.style.position = 'absolute';+ tempInput.style.left = '-9999px';+ tempInput.value = this.inviteLink;+ document.body.appendChild(tempInput);++ // Select and copy+ tempInput.select();+ tempInput.setSelectionRange(0, 99999); // For mobile devices++ const successful = document.execCommand('copy');+ document.body.removeChild(tempInput);++ if (successful) {+ showSuccessInfo('✅ Invite link copied to clipboard!');+ } else {+ showErrorInfo('❌ Failed to copy. Please select and copy manually.');+ }+ } catch (err) {+ console.error('Fallback copy failed:', err);+ showErrorInfo('❌ Failed to copy. Please select and copy manually.');+ }+ },+ closeModal() {+ $('#modalGroupGetInviteLink').modal('hide');+ },+ handleGroupIDInput() {+ // Auto-correct the input if it's just numbers+ const input = this.group_id.trim();+ if (input && !input.includes('@') && !input.includes('g.us')) {+ // If it's just numbers, assume it's a group ID+ this.group_id = input + window.TYPEGROUP;+ }+ }+ },+ template: `+ <div class="green card" @click="openModal" style="cursor: pointer;">+ <div class="content">+ <a class="ui green right ribbon label">Group</a>+ <div class="header">Get Group Invite Link</div>+ <div class="description">+ Get invite link for a group+ </div>+ </div>+ </div>++ <!-- Modal -->+ <div class="ui modal" id="modalGroupGetInviteLink">+ <i class="close icon"></i>+ <div class="header">+ <i class="linkify icon"></i>+ Get Group Invite Link+ </div>+ <div class="content">+ <form class="ui form">+ <div class="field">+ <label>Group ID</label>+ <input type="text" v-model="group_id"+ placeholder="Enter group ID (e.g., 120363419080717833)"+ @blur="handleGroupIDInput"+ @input="handleGroupIDInput">+ <div class="ui tiny info message">+ <i class="info circle icon"></i>+ <div class="content">+ <p>You can enter just the numbers (e.g., 120363419080717833) - the @g.us suffix will be added automatically.</p>+ </div>+ </div>+ <div v-if="group_id && displayGroupID !== group_id" class="ui info message">+ <i class="info circle icon"></i>+ <div class="content">+ <div class="header">Auto-corrected Group ID</div>+ <p>Your input: <code>{{ group_id }}</code></p>+ <p>Will use: <code>{{ displayGroupID }}</code></p>+ </div>+ </div>+ </div>++ <div class="field">+ <div class="ui checkbox">+ <input type="checkbox" v-model="resetLink" id="resetInviteLink">+ <label for="resetInviteLink">Reset invite link (revoke old link)</label>+ </div>+ </div>++ <div class="ui divider"></div>++ <div v-if="inviteLink" class="field">+ <label>Invite Link</label>+ <div class="ui action input">+ <input type="text" :value="inviteLink" readonly+ style="font-family: monospace; background-color: #f8f9fa; cursor: text;"+ @click="$event.target.select()"+ @focus="$event.target.select()">+ <button type="button" class="ui blue button" @click="copyToClipboard" :class="{'loading': copying}">+ <i class="copy icon"></i>+ <span v-if="copying">Copying...</span>+ <span v-else>Copy</span>+ </button>+ </div>+ <div class="ui info message">+ <i class="info circle icon"></i>+ <div class="content">+ <div class="header">Invite Link Generated</div>+ <p>Share this link with others to invite them to the group.</p>+ </div>+ </div>+ </div>++ <div class="ui divider"></div>++ <button type="button" class="ui approve positive right labeled icon button"+ :class="{'loading': loading, 'disabled': !isValidForm || loading}"+ @click.prevent="handleSubmit">+ <span v-if="loading">Fetching...</span>+ <span v-else>Get Invite Link</span>+ <i class="linkify icon"></i>+ </button>+ </form>+ </div>+ <div class="actions">+ <div class="ui approve button" @click="closeModal">Close</div>+ </div>+ </div>+ `+}\ No newline at end of filediff --git a/src/views/index.html b/src/views/index.htmlindex dcfaa71c..ef9b5f19 100644--- a/src/views/index.html+++ b/src/views/index.html@@ -111,6 +111,7 @@<group-set-locked></group-set-locked><group-set-announce></group-set-announce><group-set-topic></group-set-topic>+ <group-get-invite-link></group-get-invite-link><group-info></group-info></div>@@ -211,6 +212,7 @@import GroupSetLocked from "{{ .AppBasePath }}/components/GroupSetLocked.js";import GroupSetAnnounce from "{{ .AppBasePath }}/components/GroupSetAnnounce.js";import GroupSetTopic from "{{ .AppBasePath }}/components/GroupSetTopic.js";+ import GroupGetInviteLink from "{{ .AppBasePath }}/components/GroupGetInviteLink.js";import GroupInfo from "{{ .AppBasePath }}/components/GroupInfo.js";import NewsletterList from "{{ .AppBasePath }}/components/NewsletterList.js";import AccountAvatar from "{{ .AppBasePath }}/components/AccountAvatar.js";@@ -256,7 +258,7 @@AppLogin, AppLoginWithCode, AppLogout, AppReconnect,SendMessage, SendImage, SendFile, SendVideo, SendLink, SendContact, SendLocation, SendAudio, SendPoll, SendPresence, SendChatPresence,MessageDelete, MessageUpdate, MessageReact, MessageRevoke, MessageRead,- GroupList, GroupCreate, GroupJoinWithLink, GroupInfoFromLink, GroupAddParticipants, GroupSetPhoto, GroupSetName, GroupSetLocked, GroupSetAnnounce, GroupSetTopic, GroupInfo,+ GroupList, GroupCreate, GroupJoinWithLink, GroupInfoFromLink, GroupAddParticipants, GroupSetPhoto, GroupSetName, GroupSetLocked, GroupSetAnnounce, GroupSetTopic, GroupGetInviteLink, GroupInfo,NewsletterList,AccountAvatar, AccountUserInfo, AccountPrivacy, AccountChangeAvatar, AccountContact, AccountChangePushName, AccountUserCheck, AccountBusinessProfile,ChatPinManager, ChatList, ChatMessages