Skip to content

Commit 1d128b4

Browse files
committed
fix(whatsapp): gate poll sends during reachout timelock
1 parent b337164 commit 1d128b4

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

extensions/whatsapp/src/send.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,30 @@ describe("web outbound", () => {
789789
});
790790
});
791791

792+
it("checks send readiness before sending direct polls", async () => {
793+
const assertSendReady = vi.fn(async () => {
794+
throw new Error("WhatsApp reachout timelock is active");
795+
});
796+
hoisted.controllerListeners.set("default", {
797+
assertSendReady,
798+
sendComposingTo,
799+
sendMessage,
800+
sendPoll,
801+
sendReaction,
802+
});
803+
804+
await expect(
805+
sendPollWhatsApp(
806+
"+1555",
807+
{ question: "Lunch?", options: ["Pizza", "Sushi"] },
808+
{ verbose: false, cfg: WHATSAPP_TEST_CFG },
809+
),
810+
).rejects.toThrow("WhatsApp reachout timelock is active");
811+
812+
expect(assertSendReady).toHaveBeenCalledWith("+1555");
813+
expect(sendPoll).not.toHaveBeenCalled();
814+
});
815+
792816
it("redacts recipients and poll text in outbound logs", async () => {
793817
const logPath = path.join(os.tmpdir(), `openclaw-outbound-${crypto.randomUUID()}.log`);
794818
setLoggerOverride({ level: "trace", file: logPath });

extensions/whatsapp/src/send.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ export async function sendPollWhatsApp(
378378
},
379379
"sending poll",
380380
);
381+
if (!isWhatsAppNewsletterJid(jid)) {
382+
await active.assertSendReady?.(to);
383+
}
381384
const result = await active.sendPoll(to, normalized);
382385
const messageId = (result as { messageId?: string })?.messageId ?? "unknown";
383386
const durationMs = Date.now() - startedAt;

0 commit comments

Comments
 (0)