Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(engine): baileys sendSeen + deleteChat; advertise read-receipts

rmyndharis606c370f404c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03bb0f061..4e4efd556 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,7 @@ plugins instead of in core (#265).
- **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). (#309)
+- **Baileys engine — contacts, chats, read receipts.** The Baileys engine can now list contacts (`getContacts`/`getContactById`), resolve a contact's phone (`resolveContactPhone`, best-effort), list chats (`getChats`), mark a chat read (`sendSeen`), and delete a chat (`deleteChat`) — backed by a per-session in-memory store fed from Baileys' contact/chat sync events (rebuilt on each connect). `getChatHistory` remains unsupported (HTTP 501): Baileys has no on-demand history API. Labels/channels/status/catalog/message-reactions stay unsupported (parity with the whatsapp-web.js engine). With this, the Baileys engine implements every neutral capability it can meaningfully support. (#PR)
### Changed
diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.ts
index 1cf8d985b..830abc944 100644
--- a/src/engine/adapters/baileys.adapter.spec.ts
+++ b/src/engine/adapters/baileys.adapter.spec.ts
@@ -162,9 +162,9 @@ describe('BaileysAdapter lifecycle & status', () => {
});
describe('BaileysAdapter capability gating', () => {
- it('throws EngineNotSupportedError for still-gated methods (e.g. sendSeen)', async () => {
+ it('throws EngineNotSupportedError for still-gated methods (e.g. getChatHistory)', async () => {
const adapter = newAdapter();
- await expect(adapter.sendSeen('[email protected]')).rejects.toBeInstanceOf(EngineNotSupportedError);
+ await expect(adapter.getChatHistory('[email protected]')).rejects.toBeInstanceOf(EngineNotSupportedError);
});
});
@@ -722,3 +722,67 @@ describe('BaileysAdapter contact + chat reads', () => {
await expect(adapter.getContacts()).rejects.toBeInstanceOf(EngineNotReadyError);
});
});
+
+describe('BaileysAdapter sendSeen + deleteChat', () => {
+ beforeEach(() => {
+ fakeSock.user = { id: '628999:[email protected]', name: 'Me' };
+ jest.clearAllMocks();
+ });
+
+ const readyWithMessage = async (): Promise<BaileysAdapter> => {
+ const adapter = newAdapter();
+ await adapter.initialize({});
+ fakeSock.fire('connection.update', { connection: 'open' });
+ fakeSock.fire('messages.upsert', {
+ type: 'notify',
+ messages: [
+ {
+ key: { remoteJid: '[email protected]', fromMe: false, id: 'M1' },
+ message: { conversation: 'hi' },
+ messageTimestamp: 1700000020,
+ },
+ ],
+ });
+ return adapter;
+ };
+
+ it('sendSeen marks the last message read and returns true', async () => {
+ const adapter = await readyWithMessage();
+ const ok = await adapter.sendSeen('[email protected]');
+ expect(ok).toBe(true);
+ expect(fakeSock.readMessages).toHaveBeenCalledWith([
+ { remoteJid: '[email protected]', fromMe: false, id: 'M1' },
+ ]);
+ });
+
+ it('sendSeen returns false when no last message is known', async () => {
+ const adapter = newAdapter();
+ await adapter.initialize({});
+ fakeSock.fire('connection.update', { connection: 'open' });
+ expect(await adapter.sendSeen('[email protected]')).toBe(false);
+ expect(fakeSock.readMessages).not.toHaveBeenCalled();
+ });
+
+ it('deleteChat revokes the chat via chatModify with the last message', async () => {
+ const adapter = await readyWithMessage();
+ const ok = await adapter.deleteChat('[email protected]');
+ expect(ok).toBe(true);
+ expect(fakeSock.chatModify).toHaveBeenCalledWith(
+ {
+ delete: true,
+ lastMessages: [
+ { key: { remoteJid: '[email protected]', fromMe: false, id: 'M1' }, messageTimestamp: 1700000020 },
+ ],
+ },
+ );
+ });
+
+ it('deleteChat returns false when no last message is known', async () => {
+ const adapter = newAdapter();
+ await adapter.initialize({});
+ fakeSock.fire('connection.update', { connection: 'open' });
+ expect(await adapter.deleteChat('[email protected]')).toBe(false);
+ expect(fakeSock.chatModify).not.toHaveBeenCalled();
+ });
+});
diff --git a/src/engine/adapters/baileys.adapter.ts b/src/engine/adapters/baileys.adapter.ts
index 27dd4f309..256be154c 100644
--- a/src/engine/adapters/baileys.adapter.ts
+++ b/src/engine/adapters/baileys.adapter.ts
@@ -485,6 +485,29 @@ export class BaileysAdapter implements IWhatsAppEngine {
}
}
+ async sendSeen(chatId: string): Promise<boolean> {
+ this.ensureReady();
+ const last = this.sessionStore.lastMessage(chatId);
+ if (!last) {
+ return false; // nothing known to mark read
+ }
+ await this.sock!.readMessages([last.key]);
+ return true;
+ }
+
+ async deleteChat(chatId: string): Promise<boolean> {
+ this.ensureReady();
+ const last = this.sessionStore.lastMessage(chatId);
+ if (!last) {
+ return false; // Baileys' delete needs the last message; can't synthesize it
+ }
+ await this.sock!.chatModify(
+ { delete: true, lastMessages: [{ key: last.key, messageTimestamp: last.timestamp }] },
+ chatId,
+ );
+ return true;
+ }
+
// ----- Gated: not supported by this minimal slice (no store) -----
/* eslint-disable @typescript-eslint/no-unused-vars */
@@ -557,12 +580,6 @@ export class BaileysAdapter implements IWhatsAppEngine {
sendCatalog(_chatId: string, _body?: string): Promise<MessageResult> {
return this.unsupported('sendCatalog');
}
- sendSeen(_chatId: string): Promise<boolean> {
- return this.unsupported('sendSeen');
- }
- deleteChat(_chatId: string): Promise<boolean> {
- return this.unsupported('deleteChat');
- }
/* eslint-enable @typescript-eslint/no-unused-vars */
// ----- Helpers -----
diff --git a/src/plugins/engines/baileys/index.spec.ts b/src/plugins/engines/baileys/index.spec.ts
index fc1cd39af..38d55f2a2 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-3a supported feature set', () => {
+ it('advertises the slice-3b supported feature set', () => {
expect(new BaileysPlugin().getFeatures()).toEqual([
'text-messages',
'typing-indicator',
@@ -49,6 +49,7 @@ describe('BaileysPlugin.createEngine (opaque config)', () => {
'message-reactions',
'message-deletion',
'group-management',
+ 'read-receipts',
]);
});
diff --git a/src/plugins/engines/baileys/index.ts b/src/plugins/engines/baileys/index.ts
index fd2692647..21e7859c8 100644
--- a/src/plugins/engines/baileys/index.ts
+++ b/src/plugins/engines/baileys/index.ts
@@ -62,6 +62,7 @@ export class BaileysPlugin implements IEnginePlugin {
'message-reactions',
'message-deletion',
'group-management',
+ 'read-receipts',
];
}
diff --git a/test/baileys-engine.e2e-spec.ts b/test/baileys-engine.e2e-spec.ts
index 15dfb2c86..66a57d1a7 100644
--- a/test/baileys-engine.e2e-spec.ts
+++ b/test/baileys-engine.e2e-spec.ts
@@ -65,6 +65,7 @@ describe('Baileys engine boot (e2e)', () => {
'message-reactions',
'message-deletion',
'group-management',
+ 'read-receipts',
]);
});
});