diff --git a/CHANGELOG.md b/CHANGELOG.md index b7f1cf22..c6c88766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Route to update the privacy settings * Route to update group subject * Route to update group description +* Route to accept invite code ### Fixed diff --git a/src/whatsapp/controllers/group.controller.ts b/src/whatsapp/controllers/group.controller.ts index 0eefa6f7..b4a3fd14 100644 --- a/src/whatsapp/controllers/group.controller.ts +++ b/src/whatsapp/controllers/group.controller.ts @@ -56,6 +56,12 @@ export class GroupController { return await this.waMonitor.waInstances[instance.instanceName].inviteInfo(inviteCode); } + public async acceptInvite(instance: InstanceDto, inviteCode: GroupInvite) { + return await this.waMonitor.waInstances[instance.instanceName].acceptInvite( + inviteCode, + ); + } + public async revokeInviteCode(instance: InstanceDto, groupJid: GroupJid) { return await this.waMonitor.waInstances[instance.instanceName].revokeInviteCode( groupJid, diff --git a/src/whatsapp/routers/group.router.ts b/src/whatsapp/routers/group.router.ts index a15f278b..6050183d 100644 --- a/src/whatsapp/routers/group.router.ts +++ b/src/whatsapp/routers/group.router.ts @@ -120,6 +120,16 @@ export class GroupRouter extends RouterBroker { res.status(HttpStatus.OK).json(response); }) + .get(this.routerPath('acceptInvite'), ...guards, async (req, res) => { + const response = await this.inviteCodeValidate({ + request: req, + schema: groupInviteSchema, + ClassRef: GroupInvite, + execute: (instance, data) => groupController.acceptInvite(instance, data), + }); + + res.status(HttpStatus.OK).json(response); + }) .put(this.routerPath('revokeInviteCode'), ...guards, async (req, res) => { const response = await this.groupValidate({ request: req, diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 8263cf85..81dfc5c9 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -1702,6 +1702,14 @@ export class WAStartupService { } } + public async acceptInvite(id: GroupInvite) { + try { + return await this.client.groupAcceptInvite(id.inviteCode); + } catch (error) { + throw new NotFoundException('No invite info', id.inviteCode); + } + } + public async revokeInviteCode(id: GroupJid) { try { const inviteCode = await this.client.groupRevokeInvite(id.groupJid);