Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(engine): thread the baileys message store into the adapter

rmyndharisc7a2e0418700
diff --git a/src/engine/engine.factory.spec.ts b/src/engine/engine.factory.spec.ts
index fc37c28a5..2bdd77306 100644
--- a/src/engine/engine.factory.spec.ts
+++ b/src/engine/engine.factory.spec.ts
@@ -1,6 +1,7 @@
import { EngineFactory } from './engine.factory';
import { ConfigService } from '@nestjs/config';
import { PluginLoaderService, PluginType } from '../core/plugins';
+import { BaileysMessageStoreService } from './adapters/baileys-message-store.service';
describe('EngineFactory', () => {
const engineBlob = {
@@ -21,6 +22,9 @@ describe('EngineFactory', () => {
return { get: jest.fn((key: string) => values[key]) } as unknown as ConfigService;
};
+ const buildMessageStore = (): BaileysMessageStoreService =>
+ ({ put: jest.fn(), getMessage: jest.fn(), clearSession: jest.fn() }) as unknown as BaileysMessageStoreService;
+
it('passes ONLY engine-neutral fields to createEngine (no Puppeteer leak)', () => {
const createEngine = jest.fn().mockReturnValue({});
const pluginInstance = { type: PluginType.ENGINE, createEngine };
@@ -28,7 +32,7 @@ describe('EngineFactory', () => {
getPlugin: jest.fn().mockReturnValue({ instance: pluginInstance }),
} as unknown as PluginLoaderService;
- const factory = new EngineFactory(buildConfigService(), pluginLoader);
+ const factory = new EngineFactory(buildConfigService(), pluginLoader, buildMessageStore());
factory.create({ sessionId: 'sess-1', proxyUrl: 'http://p', proxyType: 'http' });
// Plain-object (not objectContaining) assertion: any browser key (headless/puppeteerArgs/
@@ -44,7 +48,7 @@ describe('EngineFactory', () => {
getPlugin: jest.fn(),
} as unknown as PluginLoaderService;
- const factory = new EngineFactory(buildConfigService(), pluginLoader);
+ const factory = new EngineFactory(buildConfigService(), pluginLoader, buildMessageStore());
await factory.onModuleInit();
expect(registerBuiltInPlugin).toHaveBeenCalledWith(
@@ -62,7 +66,7 @@ describe('EngineFactory', () => {
getPlugin: jest.fn(),
} as unknown as PluginLoaderService;
- const factory = new EngineFactory(buildConfigService(), pluginLoader);
+ const factory = new EngineFactory(buildConfigService(), pluginLoader, buildMessageStore());
await factory.onModuleInit();
const registeredIds = registerBuiltInPlugin.mock.calls.map(call => (call as [{ id: string }])[0].id);
@@ -75,7 +79,7 @@ describe('EngineFactory', () => {
getPlugin: jest.fn().mockReturnValue(undefined),
} as unknown as PluginLoaderService;
- const factory = new EngineFactory(buildConfigService(), pluginLoader);
+ const factory = new EngineFactory(buildConfigService(), pluginLoader, buildMessageStore());
expect(() => factory.create({ sessionId: 'sess-2' })).not.toThrow();
});
});
diff --git a/src/engine/engine.factory.ts b/src/engine/engine.factory.ts
index c8709c9d0..9ea9397dd 100644
--- a/src/engine/engine.factory.ts
+++ b/src/engine/engine.factory.ts
@@ -6,6 +6,7 @@ import { PluginLoaderService, PluginType, IEnginePlugin, PluginManifest } from '
import { WhatsAppWebJsPlugin } from '../plugins/engines/whatsapp-web-js';
import { BaileysPlugin } from '../plugins/engines/baileys';
import { createLogger } from '../common/services/logger.service';
+import { BaileysMessageStoreService } from './adapters/baileys-message-store.service';
export interface EngineCreateOptions {
sessionId: string;
@@ -21,6 +22,7 @@ export class EngineFactory implements OnModuleInit {
constructor(
private readonly configService: ConfigService,
private readonly pluginLoader: PluginLoaderService,
+ private readonly baileysMessageStore: BaileysMessageStoreService,
) {
this.engineType = this.configService.get<string>('engine.type') ?? 'whatsapp-web.js';
}
@@ -60,7 +62,7 @@ export class EngineFactory implements OnModuleInit {
};
this.pluginLoader.registerBuiltInPlugin(
baileysManifest,
- new BaileysPlugin(),
+ new BaileysPlugin(this.baileysMessageStore),
this.configService.get('engine') ?? {},
);
diff --git a/src/plugins/engines/baileys/index.spec.ts b/src/plugins/engines/baileys/index.spec.ts
index ac5d33255..5a49c2303 100644
--- a/src/plugins/engines/baileys/index.spec.ts
+++ b/src/plugins/engines/baileys/index.spec.ts
@@ -50,4 +50,11 @@ describe('BaileysPlugin.createEngine (opaque config)', () => {
it('reports the baileys library name', () => {
expect(new BaileysPlugin().getEngineLibrary().name).toBe('@whiskeysockets/baileys');
});
+
+ it('passes the message store to the adapter', () => {
+ const store = { put: jest.fn(), getMessage: jest.fn(), clearSession: jest.fn() };
+ const plugin = new BaileysPlugin(store);
+ plugin.createEngine({ sessionId: 'sess-1' });
+ expect(BaileysAdapter).toHaveBeenCalledWith(expect.objectContaining({ sessionId: 'sess-1', messageStore: store }));
+ });
});
diff --git a/src/plugins/engines/baileys/index.ts b/src/plugins/engines/baileys/index.ts
index d0169f0a3..a33ec8512 100644
--- a/src/plugins/engines/baileys/index.ts
+++ b/src/plugins/engines/baileys/index.ts
@@ -6,11 +6,14 @@
import { PluginContext, PluginType, IEnginePlugin } from '../../../core/plugins';
import { IWhatsAppEngine } from '../../../engine/interfaces/whatsapp-engine.interface';
import { BaileysAdapter } from '../../../engine/adapters/baileys.adapter';
+import { BaileysMessageStore } from '../../../engine/types/baileys.types';
export class BaileysPlugin implements IEnginePlugin {
type = PluginType.ENGINE as const;
private context?: PluginContext;
+ constructor(private readonly messageStore?: BaileysMessageStore) {}
+
onLoad(context: PluginContext): Promise<void> {
this.context = context;
context.logger.log('Baileys engine plugin loaded');
@@ -43,6 +46,7 @@ export class BaileysPlugin implements IEnginePlugin {
authDir,
proxyUrl,
proxyType,
+ messageStore: this.messageStore,
});
}