Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(engine): baileys profile picture + block/unblock; advertise group-management
rmyndharis82c68b1614ae
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex be05baaf1..bf6d6a81e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -30,6 +30,7 @@ plugins instead of in core (#265).- **Baileys engine (minimal slice)** — `ENGINE_TYPE=baileys` now selects a second, browser-free WhatsApp engine built on `@whiskeysockets/baileys` (WebSocket/Noise protocol, no Chromium). This first slice supports linking (QR + pairing code), sending and receiving **text**, recipient resolution, and typing presence; all other operations return HTTP 501 until later slices add a message store. Config: `BAILEYS_AUTH_DIR` (default `./data/baileys`). Proxy is not yet supported on this engine. (#299)- **Baileys engine — media/location/contact sends.** The Baileys engine (`ENGINE_TYPE=baileys`) can now send image/video/audio/document/sticker, location, and contact messages (slice 2a). URL media is fetched through the same SSRF-guarded path as the whatsapp-web.js engine (host guard + byte cap + timeout, no redirects). Reply/forward/react/delete remain unsupported (HTTP 501) until a later slice adds a message store. (#307)- **Baileys engine — reply/forward/react/delete.** The Baileys engine can now reply to, forward, react to, and delete (revoke-for-everyone) messages, backed by a persisted per-session message store (`baileys_stored_messages`, bounded by `BAILEYS_MESSAGE_STORE_LIMIT`, default 5000). Delete-for-me and reading reactions remain unsupported (HTTP 501). Note: this engine persists recent message protos to the data database (so these operations survive restarts) — more data-at-rest than the whatsapp-web.js engine; the store is bounded per session, cleared on logout, and CASCADE-deleted with its session, and operators with retention requirements can tune `BAILEYS_MESSAGE_STORE_LIMIT`. (#308)+- **Baileys engine — group management + profile picture + block/unblock.** The Baileys engine can now list/inspect/create groups, manage participants (add/remove/promote/demote), leave a group, set its subject/description, and get/revoke its invite code, plus fetch a contact's profile picture and block/unblock contacts (slice 3a). Contacts/chats lists, read receipts, chat history, and `deleteChat` remain unsupported (HTTP 501) until a later slice adds a contact/chat store; labels/channels/status/catalog stay unsupported (parity with the whatsapp-web.js engine). (#PR)### Changeddiff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.tsindex 64c38b203..75e4fbb2b 100644--- a/src/engine/adapters/baileys.adapter.spec.ts+++ b/src/engine/adapters/baileys.adapter.spec.ts@@ -614,3 +614,34 @@ describe('BaileysAdapter group management', () => {await expect(adapter.getGroups()).rejects.toBeInstanceOf(EngineNotReadyError);});});++describe('BaileysAdapter profile + block', () => {+ beforeEach(() => {+ fakeSock.user = { id: '628999:[email protected]', name: 'Me' };+ jest.clearAllMocks();+ });++ const ready = async (): Promise<BaileysAdapter> => {+ const adapter = newAdapter();+ await adapter.initialize({});+ fakeSock.fire('connection.update', { connection: 'open' });+ return adapter;+ };++ it('getProfilePicture returns the url, or null when none', async () => {+ fakeSock.profilePictureUrl.mockResolvedValueOnce('https://pps/x.jpg');+ const adapter = await ready();+ expect(await adapter.getProfilePicture('[email protected]')).toBe('https://pps/x.jpg');+ expect(fakeSock.profilePictureUrl).toHaveBeenCalledWith('[email protected]', 'image');+ fakeSock.profilePictureUrl.mockRejectedValueOnce(new Error('no picture'));+ expect(await adapter.getProfilePicture('[email protected]')).toBeNull();+ });++ it('blockContact / unblockContact call updateBlockStatus', async () => {+ const adapter = await ready();+ await adapter.blockContact('[email protected]');+ expect(fakeSock.updateBlockStatus).toHaveBeenCalledWith('[email protected]', 'block');+ await adapter.unblockContact('[email protected]');+ expect(fakeSock.updateBlockStatus).toHaveBeenCalledWith('[email protected]', 'unblock');+ });+});diff --git a/src/engine/adapters/baileys.adapter.ts b/src/engine/adapters/baileys.adapter.tsindex 86b639b9d..62f12b5bc 100644--- a/src/engine/adapters/baileys.adapter.ts+++ b/src/engine/adapters/baileys.adapter.ts@@ -406,6 +406,25 @@ export class BaileysAdapter implements IWhatsAppEngine {return (await this.sock!.groupRevokeInvite(groupId)) ?? '';}+ async getProfilePicture(contactId: string): Promise<string | null> {+ this.ensureReady();+ try {+ return (await this.sock!.profilePictureUrl(contactId, 'image')) ?? null;+ } catch {+ return null; // no picture set, or hidden by privacy+ }+ }++ async blockContact(contactId: string): Promise<void> {+ this.ensureReady();+ await this.sock!.updateBlockStatus(contactId, 'block');+ }++ async unblockContact(contactId: string): Promise<void> {+ this.ensureReady();+ await this.sock!.updateBlockStatus(contactId, 'unblock');+ }+// ----- Gated: not supported by this minimal slice (no store) -----/* eslint-disable @typescript-eslint/no-unused-vars */@@ -424,15 +443,6 @@ export class BaileysAdapter implements IWhatsAppEngine {getChatHistory(_chatId: string, _limit?: number, _includeMedia?: boolean): Promise<IncomingMessage[]> {return this.unsupported('getChatHistory');}- getProfilePicture(_contactId: string): Promise<string | null> {- return this.unsupported('getProfilePicture');- }- blockContact(_contactId: string): Promise<void> {- return this.unsupported('blockContact');- }- unblockContact(_contactId: string): Promise<void> {- return this.unsupported('unblockContact');- }getLabels(): Promise<Label[]> {return this.unsupported('getLabels');}diff --git a/src/plugins/engines/baileys/index.spec.ts b/src/plugins/engines/baileys/index.spec.tsindex e73a6bebb..fc1cd39af 100644--- a/src/plugins/engines/baileys/index.spec.ts+++ b/src/plugins/engines/baileys/index.spec.ts@@ -37,7 +37,7 @@ describe('BaileysPlugin.createEngine (opaque config)', () => {);});- it('advertises the slice-2b supported feature set', () => {+ it('advertises the slice-3a supported feature set', () => {expect(new BaileysPlugin().getFeatures()).toEqual(['text-messages','typing-indicator',@@ -48,6 +48,7 @@ describe('BaileysPlugin.createEngine (opaque config)', () => {'message-forwarding','message-reactions','message-deletion',+ 'group-management',]);});diff --git a/src/plugins/engines/baileys/index.ts b/src/plugins/engines/baileys/index.tsindex 90ed03463..fd2692647 100644--- a/src/plugins/engines/baileys/index.ts+++ b/src/plugins/engines/baileys/index.ts@@ -61,6 +61,7 @@ export class BaileysPlugin implements IEnginePlugin {'message-forwarding','message-reactions','message-deletion',+ 'group-management',];}diff --git a/test/baileys-engine.e2e-spec.ts b/test/baileys-engine.e2e-spec.tsindex bf396e85b..15dfb2c86 100644--- a/test/baileys-engine.e2e-spec.ts+++ b/test/baileys-engine.e2e-spec.ts@@ -64,6 +64,7 @@ describe('Baileys engine boot (e2e)', () => {'message-forwarding','message-reactions','message-deletion',+ 'group-management',]);});});