Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(engine): add BaileysPlugin (IEnginePlugin) + manifest

rmyndharis2a87f9053f3b
diff --git a/src/plugins/engines/baileys/index.spec.ts b/src/plugins/engines/baileys/index.spec.ts
new file mode 100644
index 000000000..42ba937a6
--- /dev/null
+++ b/src/plugins/engines/baileys/index.spec.ts
@@ -0,0 +1,47 @@
+import type { PluginContext } from '../../../core/plugins';
+
+jest.mock('../../../engine/adapters/baileys.adapter', () => ({
+ BaileysAdapter: jest.fn().mockImplementation((config: unknown) => ({ config })),
+}));
+
+import { BaileysPlugin } from './index';
+import { BaileysAdapter } from '../../../engine/adapters/baileys.adapter';
+
+describe('BaileysPlugin.createEngine (opaque config)', () => {
+ beforeEach(() => jest.clearAllMocks());
+
+ it('reads authDir from context.config.baileys and passes neutral per-call fields', () => {
+ const plugin = new BaileysPlugin();
+ void plugin.onLoad({
+ config: { baileys: { authDir: '/data/baileys' } },
+ logger: { log: jest.fn() },
+ } as unknown as PluginContext);
+
+ plugin.createEngine({ sessionId: 'sess-1', proxyUrl: 'http://p', proxyType: 'http' });
+
+ expect(BaileysAdapter).toHaveBeenCalledWith(
+ expect.objectContaining({
+ sessionId: 'sess-1',
+ authDir: '/data/baileys',
+ proxyUrl: 'http://p',
+ proxyType: 'http',
+ }),
+ );
+ });
+
+ it('falls back to the default authDir when context has no baileys config', () => {
+ const plugin = new BaileysPlugin();
+ plugin.createEngine({ sessionId: 'sess-2' });
+ expect(BaileysAdapter).toHaveBeenCalledWith(
+ expect.objectContaining({ sessionId: 'sess-2', authDir: './data/baileys' }),
+ );
+ });
+
+ it('advertises only the minimal supported feature set', () => {
+ expect(new BaileysPlugin().getFeatures()).toEqual(['text-messages', 'typing-indicator']);
+ });
+
+ it('reports the baileys library name', () => {
+ expect(new BaileysPlugin().getEngineLibrary().name).toBe('@whiskeysockets/baileys');
+ });
+});
diff --git a/src/plugins/engines/baileys/index.ts b/src/plugins/engines/baileys/index.ts
new file mode 100644
index 000000000..21af5a7c3
--- /dev/null
+++ b/src/plugins/engines/baileys/index.ts
@@ -0,0 +1,70 @@
+/**
+ * Baileys Engine Plugin
+ * Built-in engine plugin that wraps the @whiskeysockets/baileys library (minimal slice).
+ */
+
+import { PluginContext, PluginType, IEnginePlugin } from '../../../core/plugins';
+import { IWhatsAppEngine } from '../../../engine/interfaces/whatsapp-engine.interface';
+import { BaileysAdapter } from '../../../engine/adapters/baileys.adapter';
+
+export class BaileysPlugin implements IEnginePlugin {
+ type = PluginType.ENGINE as const;
+ private context?: PluginContext;
+
+ onLoad(context: PluginContext): Promise<void> {
+ this.context = context;
+ context.logger.log('Baileys engine plugin loaded');
+ return Promise.resolve();
+ }
+
+ onEnable(context: PluginContext): Promise<void> {
+ context.logger.log('Baileys engine plugin enabled');
+ return Promise.resolve();
+ }
+
+ onDisable(context: PluginContext): Promise<void> {
+ context.logger.log('Baileys engine plugin disabled');
+ return Promise.resolve();
+ }
+
+ createEngine(config: Record<string, unknown>): IWhatsAppEngine {
+ const sessionId = config.sessionId as string;
+ const proxyUrl = config.proxyUrl as string | undefined;
+ const proxyType = config.proxyType as 'http' | 'https' | 'socks4' | 'socks5' | undefined;
+
+ // Baileys' own config namespace, read from the opaque per-engine blob the factory supplies via
+ // context.config (the `engine` sub-tree in configuration.ts). Per-call config carries only
+ // engine-neutral fields (sessionId, proxy).
+ const engineConfig = (this.context?.config ?? {}) as { baileys?: { authDir?: string } };
+ const authDir = engineConfig.baileys?.authDir ?? './data/baileys';
+
+ return new BaileysAdapter({
+ sessionId,
+ authDir,
+ proxyUrl,
+ proxyType,
+ });
+ }
+
+ getFeatures(): string[] {
+ // Minimal slice: text send/receive + typing presence. Everything else throws 501.
+ return ['text-messages', 'typing-indicator'];
+ }
+
+ getEngineLibrary(): { name: string; version: string } {
+ let version = 'unknown';
+ try {
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
+ version = (require('@whiskeysockets/baileys/package.json') as { version: string }).version;
+ } catch {
+ // Keep 'unknown' if the package metadata can't be resolved at runtime.
+ }
+ return { name: '@whiskeysockets/baileys', version };
+ }
+
+ healthCheck(): Promise<{ healthy: boolean; message?: string }> {
+ return Promise.resolve({ healthy: true, message: 'Baileys engine is available' });
+ }
+}
+
+export default BaileysPlugin;
diff --git a/src/plugins/engines/baileys/manifest.json b/src/plugins/engines/baileys/manifest.json
new file mode 100644
index 000000000..14adc10d1
--- /dev/null
+++ b/src/plugins/engines/baileys/manifest.json
@@ -0,0 +1,21 @@
+{
+ "id": "baileys",
+ "name": "Baileys Engine",
+ "version": "1.0.0",
+ "type": "engine",
+ "description": "Baileys (WebSocket, no-browser) engine adapter for OpenWA — minimal slice: text send/receive",
+ "author": "OpenWA Team",
+ "main": "index.ts",
+ "provides": ["whatsapp-engine", "text-messages"],
+ "configSchema": {
+ "type": "object",
+ "properties": {
+ "authDir": {
+ "type": "string",
+ "title": "Auth Directory",
+ "description": "Base directory for Baileys multi-file auth state (per-session subdirs)",
+ "default": "./data/baileys"
+ }
+ }
+ }
+}