Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(baileys): cover edits made from the account's own phone
Yudhi Armyndharis31a89fc7f2d4
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 3a4939f10..75c13911d 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -7275,7 +7275,7 @@ These are the events OpenWA actually emits. A webhook is registered with an `eve>> WhatsApp encrypts every RSVP with a key derived from the event creation message, so only answers to events **this session received and still holds in its message store** can be reported: an event posted before the number was linked, or one evicted past `BAILEYS_MESSAGE_STORE_LIMIT`, yields no `event.response`. This covers events in groups and in 1:1 chats, with one known gap: in a 1:1 chat, an answer from the person who posted the event, whether the other person or this account answering its own event, cannot be decrypted (Baileys derives the event's creator from the chat partner's side of the chat) and is not reported. Answers given while the session was offline are reported when WhatsApp replays them on reconnect. Baileys merges the updates it receives within one short buffer window per event, so several answers to one event that arrive in the same window, even from different guests (the whole replay after a reconnect, or answers a fraction of a second apart live), arrive as the last one only. whatsapp-web.js accepts the subscription and never fires the event.-> WhatsApp also sends a contact's edit, and a reaction in some chats, encrypted under a secret carried by the message it changes. On Baileys they are read with the stored copy of that message, so `message.edited` fires for a message **this session received**, and `message.reaction` for one it received or sent, while its message store still holds it; an edit or reaction of one the store no longer holds (evicted past `BAILEYS_MESSAGE_STORE_LIMIT`, or from before the number was linked) is not delivered. whatsapp-web.js gets both already decrypted from WhatsApp Web.+> WhatsApp also sends a contact's edit, and a reaction in some chats, encrypted under a secret carried by the message it changes. On Baileys they are read with the stored copy of that message, so `message.edited` and `message.reaction` fire for a message **this session received or sent** while its message store still holds it; an edit or reaction of one the store no longer holds (evicted past `BAILEYS_MESSAGE_STORE_LIMIT`, or from before the number was linked) is not delivered. An edit the account makes from its own phone is applied under the account's own id the same way, whether it arrives as a plain or as an encrypted edit. whatsapp-web.js gets both already decrypted from WhatsApp Web.> There is **no** `contact.update` event. `presence.update` is emitted only for chats you have subscribed to (see the presence-subscription endpoint); call outcomes are reported as `call.accepted`, `call.rejected` and `call.missed` alongside `call.received`.diff --git a/docs/29-engine-capability-matrix.md b/docs/29-engine-capability-matrix.mdindex 54e8c5f76..5c70efb7b 100644--- a/docs/29-engine-capability-matrix.md+++ b/docs/29-engine-capability-matrix.md@@ -990,7 +990,9 @@ adapter boundary — none silently stubs.chats, encrypted under the secret of the message it changes, which the library does not decrypt. Theadapter reads them with the stored copy of that message (the session's message store, bounded by`BAILEYS_MESSAGE_STORE_LIMIT`), so an edit or reaction of a message the store no longer holds is not- delivered. whatsapp-web.js receives both already decrypted from WhatsApp Web.+ delivered. A message the session sent is held the same way as one it received, and an edit the+ account makes from its own phone is applied under the account's own id, plain or encrypted.+ whatsapp-web.js receives both already decrypted from WhatsApp Web.- **`muteChat` addressing.** whatsapp-web.js resolves the chat before writing and answers `400` for achatId it cannot resolve; Baileys writes the app-state patch without a lookup and answers `200` fora chat that does not exist. `pinChat` splits the same way.diff --git a/src/engine/adapters/baileys-events.spec.ts b/src/engine/adapters/baileys-events.spec.tsindex b64253966..c81407b3d 100644--- a/src/engine/adapters/baileys-events.spec.ts+++ b/src/engine/adapters/baileys-events.spec.ts@@ -1156,6 +1156,24 @@ describe('BaileysEvents encrypted edits and reactions', () => {expect(onMessageEdited).toHaveBeenCalledWith(expect.objectContaining({ messageId: 'ORIG1', fromMe: true }));});+ it('applies an edit the account made from its phone as a plain protocol message, under its own id', async () => {+ const stored = original({ key: { id: 'ORIG1', remoteJid: group, fromMe: true } });+ const { events, onMessageEdited, recordMessageEdit } = setup({}, stored);+ const plain = {+ key: { id: 'ENV2', remoteJid: group, fromMe: true },+ messageTimestamp: 1_786_000_100,+ message: { protocolMessage: editPlain.protocolMessage },+ } as unknown as WAMessage;++ events.handleMessagesUpsert({ type: 'notify', messages: [plain] });+ await flush();++ expect(onMessageEdited).toHaveBeenCalledWith(+ expect.objectContaining({ messageId: 'ORIG1', body: 'new text', fromMe: true }),+ );+ expect(recordMessageEdit).toHaveBeenCalledWith(group, 'ORIG1', 'new text');+ });+it('reads an edit of a message that is still being processed, with the secret that copy carries', async () => {// The original's repeat-delivery check never settles until released, which keeps it in flight; the// edit's own read of the store answers nothing.