Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(engine): surface three Baileys refusals instead of reporting success

Yudhi Armyndharis696e414be2a1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71d4e5996..c0ed4ef04 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- Three Baileys operations answer the refusal they were hiding: leaving a group and unsubscribing from a channel map WhatsApp's rejection like their sibling writes already did, and labelling a channel is refused outright instead of reporting success while nothing was labelled.
- A message's delivery status is announced, not only coloured. `delivered` and `read` render the same double check and differed only by a blue that measured 2.13:1 on the outgoing bubble, so the distinction reached neither screen readers nor colour-blind readers.
- Text rendered in a brand or status colour meets AA on the light theme. As foregrounds they measured 1.98:1 (brand), 2.15:1 (warning), 2.28:1 (success) and 3.76:1 (error); darkened `-text` twins now carry text and icons while the originals stay the fill colour. Each clears 4.5:1 against the tint its own badges paint behind it, not just against white. Dark theme is unchanged.
- The filter builder's three selects, the status image picker and the templates session picker expose accessible names, so a screen reader no longer announces unnamed comboboxes on those surfaces.
diff --git a/src/engine/adapters/baileys-channels.ts b/src/engine/adapters/baileys-channels.ts
index 0b95ff9f5..46c949929 100644
--- a/src/engine/adapters/baileys-channels.ts
+++ b/src/engine/adapters/baileys-channels.ts
@@ -78,7 +78,9 @@ export class BaileysChannels {
if (!meta) {
throw new ChannelNotFoundError(inviteCode);
}
- await this.bounded(this.sock().newsletterFollow(meta.id), 'the channel subscribe');
+ await mapServerRefusal('Subscribing to the channel', () =>
+ this.bounded(this.sock().newsletterFollow(meta.id), 'the channel subscribe'),
+ );
return this.toChannel(meta);
}
@@ -159,7 +161,11 @@ export class BaileysChannels {
async unsubscribeFromChannel(channelId: string): Promise<void> {
this.host.ensureReady();
- await this.bounded(this.sock().newsletterUnfollow(channelId), 'the channel unsubscribe');
+ // The other channel writes map WhatsApp's refusal; this one did not, so unfollowing a channel
+ // the account no longer follows answered 500 where whatsapp-web.js answers the documented 403.
+ await mapServerRefusal('Unsubscribing from the channel', () =>
+ this.bounded(this.sock().newsletterUnfollow(channelId), 'the channel unsubscribe'),
+ );
}
/** Map a Baileys NewsletterMetadata to the neutral Channel shape (optionals only when present). */
diff --git a/src/engine/adapters/baileys-groups.ts b/src/engine/adapters/baileys-groups.ts
index b770648ca..277d24a23 100644
--- a/src/engine/adapters/baileys-groups.ts
+++ b/src/engine/adapters/baileys-groups.ts
@@ -249,7 +249,12 @@ export class BaileysGroups {
async leaveGroup(groupId: string): Promise<void> {
this.host.ensureReady();
- await this.confirmed(this.sock().groupLeave(groupId), 'leaving the group');
+ // Wrapped like every other group write in this file. Without it WhatsApp's refusal for an
+ // unknown or already-left group reached the client as an opaque 500, while whatsapp-web.js
+ // resolves the chat first and answers 404.
+ await mapServerRefusal('Leaving the group', () =>
+ this.confirmed(this.sock().groupLeave(groupId), 'leaving the group'),
+ );
}
async setGroupSubject(groupId: string, subject: string): Promise<void> {
diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.ts
index abc620263..029ac4d70 100644
--- a/src/engine/adapters/baileys.adapter.spec.ts
+++ b/src/engine/adapters/baileys.adapter.spec.ts
@@ -142,6 +142,7 @@ import { EngineRefusedError } from '../../common/errors/engine-refused.error';
import { InvalidInviteCodeError } from '../../common/errors/invalid-invite-code.error';
import { GroupNotFoundError } from '../../common/errors/group-not-found.error';
import { ChannelNotFoundError } from '../../common/errors/channel-not-found.error';
+import { ChatLabelsUnsupportedError } from '../../common/errors/chat-labels-unsupported.error';
import { Boom } from '@hapi/boom';
import { EngineTransportError } from '../../common/errors/engine-transport.error';
import { loadRemoteMediaBuffer } from '../../common/media/load-remote-media';
@@ -3257,6 +3258,9 @@ describe('BaileysAdapter group management', () => {
// non-admin with an error node, which reached the caller as a bare 500.
['getGroupInviteCode', (a: BaileysAdapter) => a.getGroupInviteCode('[email protected]'), 'groupInviteCode'],
['revokeGroupInviteCode', (a: BaileysAdapter) => a.revokeGroupInviteCode('[email protected]'), 'groupRevokeInvite'],
+ // Was the one group write with no refusal mapping: an unknown or already-left group answered
+ // an opaque 500 while whatsapp-web.js resolves the chat first and answers 404.
+ ['leaveGroup', (a: BaileysAdapter) => a.leaveGroup('[email protected]'), 'groupLeave'],
])('%s maps an admin-refused operation to EngineRefusedError (403)', async (_name, call, sockMethod) => {
(fakeSock as unknown as Record<string, jest.Mock>)[sockMethod].mockRejectedValueOnce(
Object.assign(new Error('not-authorized'), { data: 401 }),
@@ -3265,6 +3269,30 @@ describe('BaileysAdapter group management', () => {
await expect(call(adapter)).rejects.toBeInstanceOf(EngineRefusedError);
});
+ // The channel writes map WhatsApp's refusal; these two did not, so unfollowing a channel the
+ // account no longer follows answered 500 where whatsapp-web.js answers the documented 403.
+ it.each([
+ ['unsubscribeFromChannel', (a: BaileysAdapter) => a.unsubscribeFromChannel('120@newsletter'), 'newsletterUnfollow'],
+ ])('%s maps a refused channel write to EngineRefusedError (403)', async (_name, call, sockMethod) => {
+ (fakeSock as unknown as Record<string, jest.Mock>)[sockMethod].mockRejectedValueOnce(
+ Object.assign(new Error('not-authorized'), { data: 401 }),
+ );
+ const adapter = await ready();
+ await expect(call(adapter)).rejects.toBeInstanceOf(EngineRefusedError);
+ });
+
+ // Labels are a Business chat feature with no channel equivalent: whatsapp-web.js refuses the jid,
+ // this engine forwarded it and reported success while nothing was labelled.
+ it.each([
+ ['addLabelToChat', (a: BaileysAdapter) => a.addLabelToChat('120@newsletter', 'L1')],
+ ['removeLabelFromChat', (a: BaileysAdapter) => a.removeLabelFromChat('120@newsletter', 'L1')],
+ ])('%s refuses a channel jid instead of reporting success', async (_name, call) => {
+ const adapter = await ready();
+ await expect(call(adapter)).rejects.toBeInstanceOf(ChatLabelsUnsupportedError);
+ expect(fakeSock.addChatLabel).not.toHaveBeenCalled();
+ expect(fakeSock.removeChatLabel).not.toHaveBeenCalled();
+ });
+
it('a transport death on a group write propagates untouched — not folded into a 403', async () => {
const connectionClosed = new Boom('Connection Closed', { statusCode: 428 });
fakeSock.groupUpdateSubject.mockRejectedValueOnce(connectionClosed);
diff --git a/src/engine/adapters/baileys.adapter.ts b/src/engine/adapters/baileys.adapter.ts
index 061389232..2f78c75ea 100644
--- a/src/engine/adapters/baileys.adapter.ts
+++ b/src/engine/adapters/baileys.adapter.ts
@@ -1,4 +1,6 @@
import * as path from 'path';
+import { ChatLabelsUnsupportedError } from '../../common/errors/chat-labels-unsupported.error';
+import { isChannelJid } from '../identity/wa-id';
import type * as BaileysLib from '@whiskeysockets/baileys';
import type { WASocket } from '@whiskeysockets/baileys';
import { BaileysChannels } from './baileys-channels';
@@ -580,8 +582,20 @@ export class BaileysAdapter implements IWhatsAppEngine {
// Fold @c.us -> @s.whatsapp.net first: chatModify (which both calls wrap) keys the label
// app-state index by the RAW jid, so a neutral @c.us would label a phantom chat the phone never
// reads — reported as success. Same class of no-op the deleteForMe/star folds fixed.
+ /**
+ * Labels are a Business-account chat feature and WhatsApp has no concept of labelling a channel.
+ * whatsapp-web.js refuses a channel jid outright; this engine forwarded it and answered success
+ * while nothing was labelled, so the same request reported two different outcomes per engine.
+ */
+ private assertLabelable(chatId: string): void {
+ if (isChannelJid(chatId)) {
+ throw new ChatLabelsUnsupportedError('Channels do not support chat labels.');
+ }
+ }
+
async addLabelToChat(chatId: string, labelId: string): Promise<void> {
this.ensureReady();
+ this.assertLabelable(chatId);
await withQueryDeadline(
this.sock!.addChatLabel(this.sessionStore.toEngineJid(chatId), labelId),
BAILEYS_QUERY_BUDGET_MS,
@@ -590,6 +604,7 @@ export class BaileysAdapter implements IWhatsAppEngine {
}
async removeLabelFromChat(chatId: string, labelId: string): Promise<void> {
this.ensureReady();
+ this.assertLabelable(chatId);
await withQueryDeadline(
this.sock!.removeChatLabel(this.sessionStore.toEngineJid(chatId), labelId),
BAILEYS_QUERY_BUDGET_MS,