Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(engine): baileys location + contact sends; advertise media features

rmyndharisc9252a11eba1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 16411ac19..de9cc3a46 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@ plugins instead of in core (#265).
- **`auto-reply` reference extension plugin**, first-party and **registered disabled by default** — enable
it via `POST /plugins/auto-reply/enable` to exercise the capability layer end-to-end. (#294)
- **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. (#PR)
### Changed
diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.ts
index 02301915b..320228bf5 100644
--- a/src/engine/adapters/baileys.adapter.spec.ts
+++ b/src/engine/adapters/baileys.adapter.spec.ts
@@ -150,6 +150,48 @@ describe('BaileysAdapter capability gating', () => {
});
});
+describe('BaileysAdapter location + contact sends', () => {
+ beforeEach(() => {
+ fakeSock.user = { id: '628999:[email protected]', name: 'Me' };
+ jest.clearAllMocks();
+ fakeSock.sendMessage.mockResolvedValue({ key: { id: 'M2' }, messageTimestamp: 1700000006 });
+ });
+
+ const ready = async (): Promise<BaileysAdapter> => {
+ const adapter = newAdapter();
+ await adapter.initialize({});
+ fakeSock.fire('connection.update', { connection: 'open' });
+ return adapter;
+ };
+
+ it('sendLocationMessage maps lat/long + optional name/address', async () => {
+ const adapter = await ready();
+ await adapter.sendLocationMessage('[email protected]', {
+ latitude: 24.12,
+ longitude: 55.11,
+ description: 'Office',
+ address: '1 Main St',
+ });
+ expect(fakeSock.sendMessage).toHaveBeenCalledWith('[email protected]', {
+ location: { degreesLatitude: 24.12, degreesLongitude: 55.11, name: 'Office', address: '1 Main St' },
+ });
+ });
+
+ it('sendContactMessage builds a vCard with the waid', async () => {
+ const adapter = await ready();
+ await adapter.sendContactMessage('[email protected]', { name: 'John Doe', number: '+1 234-567' });
+ const [, call] = fakeSock.sendMessage.mock.calls[0] as [
+ string,
+ { contacts: { displayName: string; contacts: { vcard: string }[] } },
+ ];
+ expect(call.contacts.displayName).toBe('John Doe');
+ const vcard = call.contacts.contacts[0].vcard;
+ expect(vcard).toContain('FN:John Doe');
+ expect(vcard).toContain('waid=1234567:+1 234-567');
+ expect(vcard.startsWith('BEGIN:VCARD')).toBe(true);
+ });
+});
+
describe('BaileysAdapter messaging', () => {
beforeEach(() => {
fakeSock.user = { id: '628999:[email protected]', name: 'Me' };
diff --git a/src/engine/adapters/baileys.adapter.ts b/src/engine/adapters/baileys.adapter.ts
index 29152e38c..05980eef4 100644
--- a/src/engine/adapters/baileys.adapter.ts
+++ b/src/engine/adapters/baileys.adapter.ts
@@ -280,15 +280,28 @@ export class BaileysAdapter implements IWhatsAppEngine {
return this.sendContent(chatId, { sticker: data });
}
+ async sendLocationMessage(chatId: string, location: LocationInput): Promise<MessageResult> {
+ this.ensureReady();
+ return this.sendContent(chatId, {
+ location: {
+ degreesLatitude: location.latitude,
+ degreesLongitude: location.longitude,
+ name: location.description,
+ address: location.address,
+ },
+ });
+ }
+
+ async sendContactMessage(chatId: string, contact: ContactCard): Promise<MessageResult> {
+ this.ensureReady();
+ return this.sendContent(chatId, {
+ contacts: { displayName: contact.name, contacts: [{ vcard: this.buildVCard(contact) }] },
+ });
+ }
+
// ----- Gated: not supported by this minimal slice (no store) -----
/* eslint-disable @typescript-eslint/no-unused-vars */
- sendLocationMessage(_chatId: string, _location: LocationInput): Promise<MessageResult> {
- return this.unsupported('sendLocationMessage');
- }
- sendContactMessage(_chatId: string, _contact: ContactCard): Promise<MessageResult> {
- return this.unsupported('sendContactMessage');
- }
replyToMessage(_chatId: string, _quotedMsgId: string, _text: string): Promise<MessageResult> {
return this.unsupported('replyToMessage');
}
@@ -510,6 +523,18 @@ export class BaileysAdapter implements IWhatsAppEngine {
return { data: Buffer.from(media.data, 'base64'), mimetype: media.mimetype };
}
+ /** Build a minimal WhatsApp-compatible vCard from a neutral contact card. */
+ private buildVCard(contact: ContactCard): string {
+ const waid = contact.number.replace(/\D/g, '');
+ return [
+ 'BEGIN:VCARD',
+ 'VERSION:3.0',
+ `FN:${contact.name}`,
+ `TEL;type=CELL;type=VOICE;waid=${waid}:${contact.number}`,
+ 'END:VCARD',
+ ].join('\n');
+ }
+
/** Send a Baileys content object and shape the result like the other sends. */
private async sendContent(chatId: string, content: AnyMessageContent): Promise<MessageResult> {
const sent = await this.sock!.sendMessage(chatId, content);
diff --git a/src/plugins/engines/baileys/index.spec.ts b/src/plugins/engines/baileys/index.spec.ts
index 42ba937a6..ac5d33255 100644
--- a/src/plugins/engines/baileys/index.spec.ts
+++ b/src/plugins/engines/baileys/index.spec.ts
@@ -37,8 +37,14 @@ describe('BaileysPlugin.createEngine (opaque config)', () => {
);
});
- it('advertises only the minimal supported feature set', () => {
- expect(new BaileysPlugin().getFeatures()).toEqual(['text-messages', 'typing-indicator']);
+ it('advertises the slice-2a supported feature set', () => {
+ expect(new BaileysPlugin().getFeatures()).toEqual([
+ 'text-messages',
+ 'typing-indicator',
+ 'media-messages',
+ 'location-messages',
+ 'contact-messages',
+ ]);
});
it('reports the baileys library name', () => {
diff --git a/src/plugins/engines/baileys/index.ts b/src/plugins/engines/baileys/index.ts
index 21af5a7c3..d0169f0a3 100644
--- a/src/plugins/engines/baileys/index.ts
+++ b/src/plugins/engines/baileys/index.ts
@@ -47,8 +47,7 @@ export class BaileysPlugin implements IEnginePlugin {
}
getFeatures(): string[] {
- // Minimal slice: text send/receive + typing presence. Everything else throws 501.
- return ['text-messages', 'typing-indicator'];
+ return ['text-messages', 'typing-indicator', 'media-messages', 'location-messages', 'contact-messages'];
}
getEngineLibrary(): { name: string; version: string } {