Skip to content

Commit 269e1ad

Browse files
committed
fix(whatsapp): reject conflicting mutation targets
1 parent 645bdf9 commit 269e1ad

4 files changed

Lines changed: 167 additions & 221 deletions

File tree

‎docs/cli/message.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ unresolved SecretRef on the selected channel/account fails the action closed.
7575
| `read` | Discord, Matrix, Microsoft Teams, Slack | `--target` | `--limit`, `--message-id`, `--before`, `--after`. Discord: `--around`, `--include-thread`. Slack: `--message-id` reads a specific timestamp, combine with `--thread-id` for an exact thread reply. |
7676
| `edit` | Discord, Matrix, Microsoft Teams, Slack, Telegram, WhatsApp | `--message-id`, `--message`, `--target` | Telegram forum threads use `--thread-id`. WhatsApp edits bot-owned sent messages. |
7777
| `delete` | Discord, Matrix, Microsoft Teams, Slack, Telegram, WhatsApp | `--message-id`, `--target` | WhatsApp deletes/revokes bot-owned sent messages; `unsend` is also accepted as a WhatsApp alias. |
78-
| `unsend` | WhatsApp | `--message-id`, `--target` | Alias for WhatsApp bot-owned message delete/revoke. |
78+
| `unsend` | iMessage, WhatsApp | `--message-id`, `--target` | iMessage unsends private-API messages when available. WhatsApp accepts `unsend` as a bot-owned message delete/revoke alias. |
7979
| `pin` / `unpin` | Discord, Matrix, Microsoft Teams, Slack | `--message-id`, `--target` | `unpin` also accepts `--pinned-message-id` (Microsoft Teams: the pin/list-pins resource id, not the chat message id). |
8080
| `pins` (list) | Discord, Matrix, Microsoft Teams, Slack | `--target` | `--limit`. |
8181
| `permissions` | Discord, Matrix | `--target` | Matrix: available only when encryption is enabled and verification actions are allowed. |

‎extensions/whatsapp/src/action-runtime.test.ts‎

Lines changed: 55 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -328,114 +328,91 @@ describe("handleWhatsAppAction", () => {
328328
});
329329
});
330330

331-
it("edits own WhatsApp messages through the resolved account", async () => {
332-
await handleWhatsAppAction(
333-
{
331+
it.each([
332+
{
333+
name: "edits own WhatsApp messages through the resolved account",
334+
params: {
334335
action: "edit",
335336
chatJid: "[email protected]",
336337
messageId: "msg1",
337338
message: "updated text",
338339
},
339-
enabledConfig,
340-
);
340+
expectedEditText: "updated text",
341+
},
342+
{
343+
name: "accepts text as an edit message alias",
344+
params: {
345+
action: "edit",
346+
chatJid: "[email protected]",
347+
messageId: "msg1",
348+
text: "updated text",
349+
},
350+
expectedEditText: "updated text",
351+
},
352+
])("$name", async ({ params, expectedEditText }) => {
353+
await handleWhatsAppAction(params, enabledConfig);
341354

342355
expect(editMessageWhatsApp).toHaveBeenLastCalledWith(
343356
"+123",
344357
"msg1",
345-
"updated text",
358+
expectedEditText,
346359
expect.objectContaining({
347360
verbose: false,
348361
accountId: DEFAULT_ACCOUNT_ID,
349362
}),
350363
);
351364
});
352365

353-
it("accepts text as an edit message alias", async () => {
354-
await handleWhatsAppAction(
355-
{
366+
it.each([
367+
{
368+
name: "rejects missing edit text as a tool input error",
369+
params: {
356370
action: "edit",
357371
chatJid: "[email protected]",
358372
messageId: "msg1",
359-
text: "updated text",
360373
},
361-
enabledConfig,
362-
);
363-
364-
expect(editMessageWhatsApp).toHaveBeenLastCalledWith(
365-
"+123",
366-
"msg1",
367-
"updated text",
368-
expect.any(Object),
369-
);
370-
});
371-
372-
it("rejects missing edit text as a tool input error", async () => {
373-
await expect(
374-
handleWhatsAppAction(
375-
{
376-
action: "edit",
377-
chatJid: "[email protected]",
378-
messageId: "msg1",
379-
},
380-
enabledConfig,
381-
),
382-
).rejects.toMatchObject({
383-
name: "ToolInputError",
384-
status: 400,
385-
});
386-
expect(editMessageWhatsApp).not.toHaveBeenCalled();
387-
});
388-
389-
it("rejects empty edit text as a tool input error", async () => {
390-
await expect(
391-
handleWhatsAppAction(
392-
{
393-
action: "edit",
394-
chatJid: "[email protected]",
395-
messageId: "msg1",
396-
message: " ",
397-
},
398-
enabledConfig,
399-
),
400-
).rejects.toMatchObject({
401-
message: expect.stringMatching(/edit text cannot be empty/),
374+
},
375+
{
376+
name: "rejects empty edit text as a tool input error",
377+
params: {
378+
action: "edit",
379+
chatJid: "[email protected]",
380+
messageId: "msg1",
381+
message: " ",
382+
},
383+
message: /edit text cannot be empty/,
384+
},
385+
])("$name", async ({ params, message }) => {
386+
await expect(handleWhatsAppAction(params, enabledConfig)).rejects.toMatchObject({
387+
...(message ? { message: expect.stringMatching(message) } : {}),
402388
name: "ToolInputError",
403389
status: 400,
404390
});
405391
expect(editMessageWhatsApp).not.toHaveBeenCalled();
406392
});
407393

408-
it("unsends own WhatsApp messages through the resolved account", async () => {
409-
await handleWhatsAppAction(
410-
{
411-
action: "unsend",
412-
chatJid: "[email protected]",
413-
messageId: "msg1",
414-
},
415-
enabledConfig,
416-
);
417-
418-
expect(unsendMessageWhatsApp).toHaveBeenLastCalledWith(
419-
"+123",
420-
"msg1",
421-
expect.objectContaining({
422-
verbose: false,
423-
accountId: DEFAULT_ACCOUNT_ID,
424-
}),
425-
);
426-
});
427-
428-
it("deletes own WhatsApp messages as an unsend alias", async () => {
394+
it.each([
395+
{
396+
name: "unsends own WhatsApp messages through the resolved account",
397+
action: "unsend",
398+
expectedDetails: { ok: true, unsent: true, messageId: "msg1" },
399+
},
400+
{
401+
name: "deletes own WhatsApp messages as an unsend alias",
402+
action: "delete",
403+
expectedDetails: { ok: true, deleted: true, messageId: "msg1" },
404+
},
405+
])("$name", async ({ action, expectedDetails }) => {
429406
const result = await handleWhatsAppAction(
430407
{
431-
action: "delete",
408+
action,
432409
chatJid: "[email protected]",
433410
messageId: "msg1",
434411
},
435412
enabledConfig,
436413
);
437414

438-
expect(result.details).toEqual({ ok: true, deleted: true, messageId: "msg1" });
415+
expect(result.details).toEqual(expectedDetails);
439416
expect(unsendMessageWhatsApp).toHaveBeenLastCalledWith(
440417
"+123",
441418
"msg1",
@@ -446,41 +423,21 @@ describe("handleWhatsAppAction", () => {
446423
);
447424
});
448425

449-
it("respects sendMessage gating for edit, delete, and unsend", async () => {
426+
it.each(["edit", "delete", "unsend"])("respects sendMessage gating for %s", async (action) => {
450427
const cfg = {
451428
channels: { whatsapp: { actions: { sendMessage: false } } },
452429
} as OpenClawConfig;
453430

454431
await expect(
455432
handleWhatsAppAction(
456433
{
457-
action: "edit",
458-
chatJid: "[email protected]",
459-
messageId: "msg1",
460-
message: "updated",
461-
},
462-
cfg,
463-
),
464-
).rejects.toThrow(/message edit is disabled/);
465-
await expect(
466-
handleWhatsAppAction(
467-
{
468-
action: "delete",
469-
chatJid: "[email protected]",
470-
messageId: "msg1",
471-
},
472-
cfg,
473-
),
474-
).rejects.toThrow(/message delete is disabled/);
475-
await expect(
476-
handleWhatsAppAction(
477-
{
478-
action: "unsend",
434+
action,
479435
chatJid: "[email protected]",
480436
messageId: "msg1",
437+
...(action === "edit" ? { message: "updated" } : {}),
481438
},
482439
cfg,
483440
),
484-
).rejects.toThrow(/message unsend is disabled/);
441+
).rejects.toThrow(new RegExp(`message ${action} is disabled`));
485442
});
486443
});

0 commit comments

Comments
 (0)