Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(wwebjs): answer 404 for membership requests on a non-group id

Yudhi Armyndharisebfd087141e4
diff --git a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
index 6dcb78ee6..d674226ab 100644
--- a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
+++ b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
@@ -6703,7 +6703,8 @@ describe('WhatsAppWebJsAdapter group join + settings + own profile', () => {
// The nine write routes that previously threw a bare Error('Chat is not a group') for a
// non-group id (surfacing as an opaque 500) now share this guard: unknown id, 1:1 id and
- // status id are all GroupNotFoundError (404), like the guarded settings writes above.
+ // status id are all GroupNotFoundError (404), like the guarded settings writes above. The
+ // membership-request approve/reject writes went straight to the page and answered 500 the same way.
it.each([
['addParticipants', (a: WhatsAppWebJsAdapter) => a.addParticipants('[email protected]', ['[email protected]'])],
['removeParticipants', (a: WhatsAppWebJsAdapter) => a.removeParticipants('[email protected]', ['[email protected]'])],
@@ -6714,6 +6715,16 @@ describe('WhatsAppWebJsAdapter group join + settings + own profile', () => {
['setGroupDescription', (a: WhatsAppWebJsAdapter) => a.setGroupDescription('[email protected]', 'New description')],
['getGroupInviteCode', (a: WhatsAppWebJsAdapter) => a.getGroupInviteCode('[email protected]')],
['revokeGroupInviteCode', (a: WhatsAppWebJsAdapter) => a.revokeGroupInviteCode('[email protected]')],
+ ['approveGroupMembershipRequests', (a: WhatsAppWebJsAdapter) => a.approveGroupMembershipRequests('[email protected]')],
+ ['rejectGroupMembershipRequests', (a: WhatsAppWebJsAdapter) => a.rejectGroupMembershipRequests('[email protected]')],
+ [
+ 'approveGroupMembershipRequests (named)',
+ (a: WhatsAppWebJsAdapter) => a.approveGroupMembershipRequests('[email protected]', ['[email protected]']),
+ ],
+ [
+ 'rejectGroupMembershipRequests (named)',
+ (a: WhatsAppWebJsAdapter) => a.rejectGroupMembershipRequests('[email protected]', ['[email protected]']),
+ ],
])('%s answers 404 (GroupNotFoundError) when the id is not a group', async (_name, call) => {
const getChatById = jest.fn().mockResolvedValue({ isGroup: false });
await expect(call(readyAdapter({ getChatById }))).rejects.toBeInstanceOf(GroupNotFoundError);
diff --git a/src/engine/adapters/wwebjs-groups.ts b/src/engine/adapters/wwebjs-groups.ts
index 47b067fca..0255e03d7 100644
--- a/src/engine/adapters/wwebjs-groups.ts
+++ b/src/engine/adapters/wwebjs-groups.ts
@@ -633,7 +633,9 @@ export class WwebjsGroups {
groupId: string,
participants?: string[],
): Promise<ParticipantOperationResult[]> {
- this.host.ensureReady();
+ // Resolved first, like the list above: the page reads the group's metadata without checking it
+ // exists, so an unknown or non-group id rejected there and answered 500 instead of 404.
+ await this.requireGroupChat(groupId, op);
const options = {
// Qualified like every other participant write in this file: the service blesses a bare phone
// number, and the page maps requesterIds straight through `createWid` (Injected/Utils.js) —