Skip to content

Commit ea9ba27

Browse files
committed
feat: Route to update group description
1 parent a28bbce commit ea9ba27

6 files changed

Lines changed: 54 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Route to fetch all privacy settings
99
* Route to update the privacy settings
1010
* Route to update group subject
11+
* Route to update group description
1112

1213
### Fixed
1314

src/validate/validate.schema.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,17 @@ export const updateGroupSubjectSchema: JSONSchema7 = {
702702
...isNotEmpty('groupJid', 'subject'),
703703
};
704704

705+
export const updateGroupDescriptionSchema: JSONSchema7 = {
706+
$id: v4(),
707+
type: 'object',
708+
properties: {
709+
groupJid: { type: 'string' },
710+
description: { type: 'string' },
711+
},
712+
required: ['groupJid', 'description'],
713+
...isNotEmpty('groupJid', 'description'),
714+
};
715+
705716
// Webhook Schema
706717
export const webhookSchema: JSONSchema7 = {
707718
$id: v4(),

src/whatsapp/controllers/group.controller.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
CreateGroupDto,
3+
GroupDescriptionDto,
34
GroupInvite,
45
GroupJid,
56
GroupPictureDto,
@@ -30,6 +31,15 @@ export class GroupController {
3031
);
3132
}
3233

34+
public async updateGroupDescription(
35+
instance: InstanceDto,
36+
update: GroupDescriptionDto,
37+
) {
38+
return await this.waMonitor.waInstances[instance.instanceName].updateGroupDescription(
39+
update,
40+
);
41+
}
42+
3343
public async findGroupInfo(instance: InstanceDto, groupJid: GroupJid) {
3444
return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid);
3545
}

src/whatsapp/dto/group.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export class GroupSubjectDto {
1414
subject: string;
1515
}
1616

17+
export class GroupDescriptionDto {
18+
groupJid: string;
19+
description: string;
20+
}
21+
1722
export class GroupJid {
1823
groupJid: string;
1924
}

src/whatsapp/routers/group.router.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
toggleEphemeralSchema,
88
updateGroupPictureSchema,
99
updateGroupSubjectSchema,
10+
updateGroupDescriptionSchema,
1011
groupInviteSchema,
1112
} from '../../validate/validate.schema';
1213
import { RouterBroker } from '../abstract/abstract.router';
@@ -16,6 +17,7 @@ import {
1617
GroupJid,
1718
GroupPictureDto,
1819
GroupSubjectDto,
20+
GroupDescriptionDto,
1921
GroupUpdateParticipantDto,
2022
GroupUpdateSettingDto,
2123
GroupToggleEphemeralDto,
@@ -57,6 +59,17 @@ export class GroupRouter extends RouterBroker {
5759

5860
res.status(HttpStatus.CREATED).json(response);
5961
})
62+
.put(this.routerPath('updateGroupDescription'), ...guards, async (req, res) => {
63+
const response = await this.groupValidate<GroupDescriptionDto>({
64+
request: req,
65+
schema: updateGroupDescriptionSchema,
66+
ClassRef: GroupDescriptionDto,
67+
execute: (instance, data) =>
68+
groupController.updateGroupDescription(instance, data),
69+
});
70+
71+
res.status(HttpStatus.CREATED).json(response);
72+
})
6073
.get(this.routerPath('findGroupInfos'), ...guards, async (req, res) => {
6174
const response = await this.groupValidate<GroupJid>({
6275
request: req,

src/whatsapp/services/whatsapp.service.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import {
101101
GroupUpdateSettingDto,
102102
GroupToggleEphemeralDto,
103103
GroupSubjectDto,
104+
GroupDescriptionDto,
104105
} from '../dto/group.dto';
105106
import { MessageUpQuery } from '../repository/messageUp.repository';
106107
import { useMultiFileAuthStateDb } from '../../utils/use-multi-file-auth-state-db';
@@ -1652,6 +1653,19 @@ export class WAStartupService {
16521653
}
16531654
}
16541655

1656+
public async updateGroupDescription(data: GroupDescriptionDto) {
1657+
try {
1658+
await this.client.groupUpdateDescription(data.groupJid, data.description);
1659+
1660+
return { update: 'success' };
1661+
} catch (error) {
1662+
throw new InternalServerErrorException(
1663+
'Error updating group description',
1664+
error.toString(),
1665+
);
1666+
}
1667+
}
1668+
16551669
public async findGroup(id: GroupJid, reply: 'inner' | 'out' = 'out') {
16561670
try {
16571671
return await this.client.groupMetadata(id.groupJid);

0 commit comments

Comments
 (0)