Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(baileys): recognise a lid-addressed creator without an own lid
Yudhi Armyndharisc2519958150c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 563dc9866..cc75ecbbb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- An ingress route whose manifest carries a non-string ack body, status or header is answered rather than failing with `500`; a manifest is third-party JSON and the loader does not type-check every leaf.- Uploading a zip whose trailer parses but whose directory does not answers `400`, not `500`.- A `socks5://` or `socks4://` proxy at an IPv6 literal connects: the brackets `URL` keeps were going on the wire as part of a hostname.+- A Baileys session whose credentials carry no LID of their own no longer reports a `group.join` for a group it created itself: every LID comparison answered false, so the creator was never recognised. The session's own LID mapping settles it instead.- Starting a session that turns out to be linked already no longer opens a QR modal over it, which then polled for a code that could never arrive. The decision now reads the list the dashboard re-reads after the start, not the state it held before it.- Escape dismisses the Chats emoji picker instead of closing the whole conversation behind it.- A click on a WhatsApp Business prompt quotes the prompt in the stored reply, so the dashboard renders the question above the answer instead of an empty quote box.diff --git a/src/engine/adapters/baileys-events.ts b/src/engine/adapters/baileys-events.tsindex 892a309c9..d997f787b 100644--- a/src/engine/adapters/baileys-events.ts+++ b/src/engine/adapters/baileys-events.ts@@ -482,7 +482,14 @@ export class BaileysEvents {const isSelf = (jid: string | undefined): boolean => {if (!jid) return false;const { kind, userPart: user } = parseWaId(jid);- return kind === 'user' ? user === phone : kind === 'lid' && user === lidUser;+ if (kind === 'user') return user === phone;+ if (kind !== 'lid') return false;+ if (lidUser !== undefined) return user === lidUser;+ // Creds carrying no `user.lid` leave nothing to compare a lid-addressed actor against, and+ // every such comparison would answer false: a group this session created would then be+ // reported as a join of itself. Fall back to the session's own lid to phone mapping, which the+ // store learns from the same traffic.+ return userPart(this.host.toNeutralJid(jid)) === phone;};for (const group of Array.isArray(groups) ? groups : []) {// Live, whatsapp-web.js emits no group.join when the session created the group, so that entry isdiff --git a/src/engine/adapters/baileys-session-store.ts b/src/engine/adapters/baileys-session-store.tsindex a776f45d8..cdfbc3b81 100644--- a/src/engine/adapters/baileys-session-store.ts+++ b/src/engine/adapters/baileys-session-store.ts@@ -206,6 +206,15 @@ export class BaileysSessionStore {* Copy own enumerable fields whose value is not `undefined`. History-sync contacts always include* `name: displayName || name || username || undefined`, and a later `{ ...existing, ...partial }`* spread would wipe a saved address-book name that arrived first via `contacts.upsert`.+ *+ * KNOWN LIMIT: a saved name therefore cannot be cleared, so a contact deleted or renamed blank on+ * the phone keeps its old name here, stays in `GET /contacts`, and (being named) is pinned against+ * eviction. Making an absent name authoritative is NOT a safe fix on its own: the same method+ * serves `contacts.update`, which Baileys emits as `{ id, notify }` for the pushname on every+ * inbound message, so absent-means-clear there would wipe the address book message by message.+ * Only an app-state `contactAction` could carry that meaning, and whether WhatsApp expresses a+ * deletion as a contactAction with empty fields is unverified here; settling it needs a live+ * account, not a guess on this path.*/private assignDefined(target: BaileysContact, source: Partial<BaileysContact>): void {for (const key of Object.keys(source) as (keyof BaileysContact)[]) {diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.tsindex 15741a8e8..93f75d66b 100644--- a/src/engine/adapters/baileys.adapter.spec.ts+++ b/src/engine/adapters/baileys.adapter.spec.ts@@ -4714,6 +4714,19 @@ describe('BaileysAdapter group events (group-participants.update / groups.updateexpect(firstEvent(onGroupEvent).groupId).toBe('[email protected]');});+ it('skips a self-created group addressed by lid when the creds carry no own lid', async () => {+ // Without `user.lid` every lid comparison answered false, so the group this session had just+ // created was reported as a join of itself. The store's own lid mapping settles it instead.+ fakeSock.user = { id: '628999:[email protected]', name: 'Me' }; // no lid on the creds+ const { onGroupEvent } = await readyWithGroupEvents();+ // The session learns its own lid from ordinary traffic, the same way every other mapping arrives.+ fakeSock.fire('lid-mapping.update', { lid: '999000@lid', pn: '[email protected]' });++ fakeSock.fire('groups.upsert', [createdGroup({ author: '999000@lid', owner: '999000@lid', authorPn: undefined })]);++ expect(onGroupEvent).not.toHaveBeenCalled();+ });+it('reports a groups.upsert entry the session authored for a group another account owns', async () => {fakeSock.user = { id: '628999:[email protected]', lid: '999000:1@lid', name: 'Me' };const { onGroupEvent } = await readyWithGroupEvents();