Skip to content

Commit a28bbce

Browse files
committed
feat: Route to update group subject
1 parent 75b48aa commit a28bbce

7 files changed

Lines changed: 62 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Route to fetch all groups that the connection is part of
88
* Route to fetch all privacy settings
99
* Route to update the privacy settings
10+
* Route to update group subject
1011

1112
### Fixed
1213

src/validate/validate.schema.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ export const toggleEphemeralSchema: JSONSchema7 = {
680680
...isNotEmpty('groupJid', 'expiration'),
681681
};
682682

683-
export const updateGroupPicture: JSONSchema7 = {
683+
export const updateGroupPictureSchema: JSONSchema7 = {
684684
$id: v4(),
685685
type: 'object',
686686
properties: {
@@ -691,6 +691,17 @@ export const updateGroupPicture: JSONSchema7 = {
691691
...isNotEmpty('groupJid', 'image'),
692692
};
693693

694+
export const updateGroupSubjectSchema: JSONSchema7 = {
695+
$id: v4(),
696+
type: 'object',
697+
properties: {
698+
groupJid: { type: 'string' },
699+
subject: { type: 'string' },
700+
},
701+
required: ['groupJid', 'subject'],
702+
...isNotEmpty('groupJid', 'subject'),
703+
};
704+
694705
// Webhook Schema
695706
export const webhookSchema: JSONSchema7 = {
696707
$id: v4(),

src/whatsapp/controllers/group.controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
GroupInvite,
44
GroupJid,
55
GroupPictureDto,
6+
GroupSubjectDto,
67
GroupToggleEphemeralDto,
78
GroupUpdateParticipantDto,
89
GroupUpdateSettingDto,
@@ -23,6 +24,12 @@ export class GroupController {
2324
);
2425
}
2526

27+
public async updateGroupSubject(instance: InstanceDto, update: GroupSubjectDto) {
28+
return await this.waMonitor.waInstances[instance.instanceName].updateGroupSubject(
29+
update,
30+
);
31+
}
32+
2633
public async findGroupInfo(instance: InstanceDto, groupJid: GroupJid) {
2734
return await this.waMonitor.waInstances[instance.instanceName].findGroup(groupJid);
2835
}

src/whatsapp/dto/chat.dto.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from "@evolution/base";
1+
import {
2+
WAPrivacyOnlineValue,
3+
WAPrivacyValue,
4+
WAReadReceiptsValue,
5+
} from '@evolution/base';
26

37
export class OnWhatsAppDto {
48
constructor(

src/whatsapp/dto/group.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export class GroupPictureDto {
99
image: string;
1010
}
1111

12+
export class GroupSubjectDto {
13+
groupJid: string;
14+
subject: string;
15+
}
16+
1217
export class GroupJid {
1318
groupJid: string;
1419
}

src/whatsapp/routers/group.router.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
updateParticipantsSchema,
66
updateSettingsSchema,
77
toggleEphemeralSchema,
8-
updateGroupPicture,
8+
updateGroupPictureSchema,
9+
updateGroupSubjectSchema,
910
groupInviteSchema,
1011
} from '../../validate/validate.schema';
1112
import { RouterBroker } from '../abstract/abstract.router';
@@ -14,6 +15,7 @@ import {
1415
GroupInvite,
1516
GroupJid,
1617
GroupPictureDto,
18+
GroupSubjectDto,
1719
GroupUpdateParticipantDto,
1820
GroupUpdateSettingDto,
1921
GroupToggleEphemeralDto,
@@ -35,10 +37,20 @@ export class GroupRouter extends RouterBroker {
3537

3638
res.status(HttpStatus.CREATED).json(response);
3739
})
40+
.put(this.routerPath('updateGroupSubject'), ...guards, async (req, res) => {
41+
const response = await this.groupValidate<GroupSubjectDto>({
42+
request: req,
43+
schema: updateGroupSubjectSchema,
44+
ClassRef: GroupSubjectDto,
45+
execute: (instance, data) => groupController.updateGroupSubject(instance, data),
46+
});
47+
48+
res.status(HttpStatus.CREATED).json(response);
49+
})
3850
.put(this.routerPath('updateGroupPicture'), ...guards, async (req, res) => {
3951
const response = await this.groupValidate<GroupPictureDto>({
4052
request: req,
41-
schema: updateGroupPicture,
53+
schema: updateGroupPictureSchema,
4254
ClassRef: GroupPictureDto,
4355
execute: (instance, data) => groupController.updateGroupPicture(instance, data),
4456
});

src/whatsapp/services/whatsapp.service.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ import {
100100
GroupUpdateParticipantDto,
101101
GroupUpdateSettingDto,
102102
GroupToggleEphemeralDto,
103+
GroupSubjectDto,
103104
} from '../dto/group.dto';
104105
import { MessageUpQuery } from '../repository/messageUp.repository';
105106
import { useMultiFileAuthStateDb } from '../../utils/use-multi-file-auth-state-db';
@@ -1631,7 +1632,23 @@ export class WAStartupService {
16311632

16321633
return { update: 'success' };
16331634
} catch (error) {
1634-
throw new InternalServerErrorException('Error creating group', error.toString());
1635+
throw new InternalServerErrorException(
1636+
'Error update group picture',
1637+
error.toString(),
1638+
);
1639+
}
1640+
}
1641+
1642+
public async updateGroupSubject(data: GroupSubjectDto) {
1643+
try {
1644+
await this.client.groupUpdateSubject(data.groupJid, data.subject);
1645+
1646+
return { update: 'success' };
1647+
} catch (error) {
1648+
throw new InternalServerErrorException(
1649+
'Error updating group subject',
1650+
error.toString(),
1651+
);
16351652
}
16361653
}
16371654

0 commit comments

Comments
 (0)