Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(groups): send the member label to the canonical group id

Yudhi Armyndhariseda27e8d4a6c
diff --git a/src/modules/group/group.service.spec.ts b/src/modules/group/group.service.spec.ts
index 18cabdd85..848f59c17 100644
--- a/src/modules/group/group.service.spec.ts
+++ b/src/modules/group/group.service.spec.ts
@@ -104,6 +104,18 @@ describe('GroupService', () => {
expect(setGroupMemberLabel).toHaveBeenNthCalledWith(2, '[email protected]', '');
});
+ 'hands the engine the group id %j in the form Baileys relays to a group',
+ async id => {
+ const setGroupMemberLabel = jest.fn().mockResolvedValue(undefined);
+ const svc = makeService({ setGroupMemberLabel });
+
+ await svc.setGroupMemberLabel('s1', id, 'Site A');
+
+ expect(setGroupMemberLabel).toHaveBeenCalledWith('[email protected]', 'Site A');
+ },
+ );
+
it('lets the whatsapp-web.js 501 through', async () => {
const svc = makeService({
setGroupMemberLabel: jest.fn().mockRejectedValue(new EngineNotSupportedError('setGroupMemberLabel')),
diff --git a/src/modules/group/group.service.ts b/src/modules/group/group.service.ts
index c69b2778d..13aab15bf 100644
--- a/src/modules/group/group.service.ts
+++ b/src/modules/group/group.service.ts
@@ -2,7 +2,7 @@ import { Injectable, BadRequestException, HttpException, HttpStatus, NotFoundExc
import { EngineRegistry } from '../../engine/engine-registry.service';
import { GroupMemberAddMode, IWhatsAppEngine, MediaInput } from '../../engine/interfaces/whatsapp-engine.interface';
import { resolveMediaBody } from '../message/media-cap.util';
-import { chatKind } from '../../engine/identity/wa-id';
+import { chatKind, toNeutralJid } from '../../engine/identity/wa-id';
import { isAddressableParticipant } from '../../engine/identity/wa-id';
import { SetGroupPictureDto } from './dto/group.dto';
import { paginate, ListOptions } from '../../common/utils/paginate';
@@ -165,7 +165,9 @@ export class GroupService {
setGroupMemberLabel(sessionId: string, groupId: string, label: string): Promise<void> {
this.assertGroupId(groupId);
- return this.getEngine(sessionId).setGroupMemberLabel(groupId, label);
+ // Baileys relays the label as a group message only to a jid whose domain is exactly `g.us`; any
+ // other spelling the check accepts (`[email protected]`, a trailing space) went out as a 1:1 message.
+ return this.getEngine(sessionId).setGroupMemberLabel(toNeutralJid(groupId), label);
}
leaveGroup(sessionId: string, groupId: string) {