diff --git a/CHANGELOG.md b/CHANGELOG.md index e924ebad..861ecbd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Route to fetch all groups that the connection is part of * Route to fetch all privacy settings * Route to update the privacy settings +* Route to update group subject ### Fixed diff --git a/src/validate/validate.schema.ts b/src/validate/validate.schema.ts index c62b1f7f..5365bb5b 100644 --- a/src/validate/validate.schema.ts +++ b/src/validate/validate.schema.ts @@ -680,7 +680,7 @@ export const toggleEphemeralSchema: JSONSchema7 = { ...isNotEmpty('groupJid', 'expiration'), }; -export const updateGroupPicture: JSONSchema7 = { +export const updateGroupPictureSchema: JSONSchema7 = { $id: v4(), type: 'object', properties: { @@ -691,6 +691,17 @@ export const updateGroupPicture: JSONSchema7 = { ...isNotEmpty('groupJid', 'image'), }; +export const updateGroupSubjectSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + groupJid: { type: 'string' }, + subject: { type: 'string' }, + }, + required: ['groupJid', 'subject'], + ...isNotEmpty('groupJid', 'subject'), +}; + // Webhook Schema export const webhookSchema: JSONSchema7 = { $id: v4(), diff --git a/src/whatsapp/controllers/group.controller.ts b/src/whatsapp/controllers/group.controller.ts index 764e26cd..51e4e3bf 100644 --- a/src/whatsapp/controllers/group.controller.ts +++ b/src/whatsapp/controllers/group.controller.ts @@ -3,6 +3,7 @@ import { GroupInvite, GroupJid, GroupPictureDto, + GroupSubjectDto, GroupToggleEphemeralDto, GroupUpdateParticipantDto, GroupUpdateSettingDto, @@ -23,6 +24,12 @@ export class GroupController { ); } + public async updateGroupSubject(instance: InstanceDto, update: GroupSubjectDto) { + return await this.waMonitor.waInstances[instance.instanceName].updateGroupSubject( + update, + ); + } + public async findGroupInfo(instance: InstanceDto, groupJid: GroupJid) { return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid); } diff --git a/src/whatsapp/dto/chat.dto.ts b/src/whatsapp/dto/chat.dto.ts index 2f65216a..d95d90ca 100644 --- a/src/whatsapp/dto/chat.dto.ts +++ b/src/whatsapp/dto/chat.dto.ts @@ -1,4 +1,8 @@ -import { WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from "@evolution/base"; +import { + WAPrivacyOnlineValue, + WAPrivacyValue, + WAReadReceiptsValue, +} from '@evolution/base'; export class OnWhatsAppDto { constructor( diff --git a/src/whatsapp/dto/group.dto.ts b/src/whatsapp/dto/group.dto.ts index 73aa14c2..db3e1ed8 100644 --- a/src/whatsapp/dto/group.dto.ts +++ b/src/whatsapp/dto/group.dto.ts @@ -9,6 +9,11 @@ export class GroupPictureDto { image: string; } +export class GroupSubjectDto { + groupJid: string; + subject: string; +} + export class GroupJid { groupJid: string; } diff --git a/src/whatsapp/routers/group.router.ts b/src/whatsapp/routers/group.router.ts index aaf0a60c..facb9dea 100644 --- a/src/whatsapp/routers/group.router.ts +++ b/src/whatsapp/routers/group.router.ts @@ -5,7 +5,8 @@ import { updateParticipantsSchema, updateSettingsSchema, toggleEphemeralSchema, - updateGroupPicture, + updateGroupPictureSchema, + updateGroupSubjectSchema, groupInviteSchema, } from '../../validate/validate.schema'; import { RouterBroker } from '../abstract/abstract.router'; @@ -14,6 +15,7 @@ import { GroupInvite, GroupJid, GroupPictureDto, + GroupSubjectDto, GroupUpdateParticipantDto, GroupUpdateSettingDto, GroupToggleEphemeralDto, @@ -35,10 +37,20 @@ export class GroupRouter extends RouterBroker { res.status(HttpStatus.CREATED).json(response); }) + .put(this.routerPath('updateGroupSubject'), ...guards, async (req, res) => { + const response = await this.groupValidate({ + request: req, + schema: updateGroupSubjectSchema, + ClassRef: GroupSubjectDto, + execute: (instance, data) => groupController.updateGroupSubject(instance, data), + }); + + res.status(HttpStatus.CREATED).json(response); + }) .put(this.routerPath('updateGroupPicture'), ...guards, async (req, res) => { const response = await this.groupValidate({ request: req, - schema: updateGroupPicture, + schema: updateGroupPictureSchema, ClassRef: GroupPictureDto, execute: (instance, data) => groupController.updateGroupPicture(instance, data), }); diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 9de6a544..e271f475 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -100,6 +100,7 @@ import { GroupUpdateParticipantDto, GroupUpdateSettingDto, GroupToggleEphemeralDto, + GroupSubjectDto, } from '../dto/group.dto'; import { MessageUpQuery } from '../repository/messageUp.repository'; import { useMultiFileAuthStateDb } from '../../utils/use-multi-file-auth-state-db'; @@ -1631,7 +1632,23 @@ export class WAStartupService { return { update: 'success' }; } catch (error) { - throw new InternalServerErrorException('Error creating group', error.toString()); + throw new InternalServerErrorException( + 'Error update group picture', + error.toString(), + ); + } + } + + public async updateGroupSubject(data: GroupSubjectDto) { + try { + await this.client.groupUpdateSubject(data.groupJid, data.subject); + + return { update: 'success' }; + } catch (error) { + throw new InternalServerErrorException( + 'Error updating group subject', + error.toString(), + ); } }