Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): report a page that dies during the wwjs LID retry
Yudhi Armyndharisa26b0d922ef8
diff --git a/src/engine/adapters/wwebjs-messaging.ts b/src/engine/adapters/wwebjs-messaging.tsindex 392657d1f..81e750fb8 100644--- a/src/engine/adapters/wwebjs-messaging.ts+++ b/src/engine/adapters/wwebjs-messaging.ts@@ -367,6 +367,8 @@ export class WwebjsMessaging {try {return await send(fresh);} catch (retryErr) {+ // The page can die during the retry as well; report it exactly as the first attempt does.+ this.host.reportIfPageTransportError(retryErr, 'sendMessage');// Same remap as the first attempt. Re-resolving the RECIPIENT says nothing about the quoted// message, so a send that reaches the page on the fresh id and only then fails on the quote// is the same caller fault — without this it would be a 500 on the retry where the identicaldiff --git a/src/engine/adapters/wwebjs-send-page-error.spec.ts b/src/engine/adapters/wwebjs-send-page-error.spec.tsindex d29166e56..fe5a29219 100644--- a/src/engine/adapters/wwebjs-send-page-error.spec.ts+++ b/src/engine/adapters/wwebjs-send-page-error.spec.ts@@ -145,6 +145,21 @@ describe('the reason a captured page failure gives the caller', () => {expect(client.sendMessage).toHaveBeenCalledTimes(2);});+ // The first attempt reports a dead page before any remap; the LID retry must too, or a page that+ // dies during the retry leaves the session READY until the watchdog notices.+ it('reports a page that dies during the LID retry', async () => {+ const { messaging, client, host } = makeMessaging();+ (host.getNumberId as jest.Mock).mockResolvedValueOnce(undefined).mockResolvedValueOnce('999@lid');+ const dead = new Error('Protocol error (Runtime.callFunctionOn): Target closed');+ client.sendMessage+ .mockRejectedValueOnce(new Error('Evaluation failed: Error: No LID for user'))+ .mockRejectedValueOnce(dead);++ await expect(messaging.sendTextMessage('[email protected]', 'hi')).rejects.toBe(dead);+ const report = (host as unknown as { reportIfPageTransportError: jest.Mock }).reportIfPageTransportError;+ expect(report).toHaveBeenCalledWith(dead, 'sendMessage');+ });+it('does not take over the recipient remap of a plain No LID failure', async () => {const { messaging, client, host } = makeMessaging();(host.getNumberId as jest.Mock).mockResolvedValue(undefined);