feat: enhance BlueBubbles message actions with support for message editing, reply metadata, and improved effect handling

This commit is contained in:
Tyler Yust
2026-01-19 23:40:22 -08:00
committed by Peter Steinberger
parent 2e6c58bf75
commit 574b848863
22 changed files with 1366 additions and 83 deletions

View File

@@ -1,4 +1,8 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { ClawdbotConfig } from "../../config/config.js";
import { setActivePluginRegistry } from "../../plugins/runtime.js";
@@ -6,7 +10,14 @@ import { createIMessageTestPlugin, createTestRegistry } from "../../test-utils/c
import { slackPlugin } from "../../../extensions/slack/src/channel.js";
import { telegramPlugin } from "../../../extensions/telegram/src/channel.js";
import { whatsappPlugin } from "../../../extensions/whatsapp/src/channel.js";
import { loadWebMedia } from "../../web/media.js";
import { runMessageAction } from "./message-action-runner.js";
import { jsonResult } from "../../agents/tools/common.js";
import type { ChannelPlugin } from "../../channels/plugins/types.js";
vi.mock("../../web/media.js", () => ({
loadWebMedia: vi.fn(),
}));
const slackConfig = {
channels: {
@@ -64,6 +75,67 @@ describe("runMessageAction context isolation", () => {
afterEach(() => {
setActivePluginRegistry(createTestRegistry([]));
});
it("maps sendAttachment media to buffer + filename", async () => {
const filePath = path.join(os.tmpdir(), `clawdbot-attachment-${Date.now()}.txt`);
await fs.writeFile(filePath, "hello");
const handleAction = vi.fn(async (ctx) => {
return jsonResult({ ok: true, params: ctx.params });
});
const testPlugin: ChannelPlugin = {
id: "bluebubbles",
meta: {
id: "bluebubbles",
label: "BlueBubbles",
selectionLabel: "BlueBubbles",
docsPath: "/channels/bluebubbles",
blurb: "BlueBubbles test plugin.",
},
capabilities: { chatTypes: ["direct", "group"], media: true },
config: {
listAccountIds: () => [],
resolveAccount: () => ({}),
},
messaging: {
targetResolver: {
looksLikeId: () => true,
hint: "<target>",
},
normalizeTarget: (raw) => raw.trim(),
},
actions: {
listActions: () => ["sendAttachment"],
handleAction: handleAction as NonNullable<ChannelPlugin["actions"]>["handleAction"],
},
};
setActivePluginRegistry(
createTestRegistry([{ pluginId: "bluebubbles", source: "test", plugin: testPlugin }]),
);
try {
const result = await runMessageAction({
cfg: { channels: { bluebubbles: {} } } as ClawdbotConfig,
action: "sendAttachment",
params: {
channel: "bluebubbles",
target: "chat_guid:TEST",
media: filePath,
},
dryRun: false,
});
expect(result.kind).toBe("action");
expect(handleAction).toHaveBeenCalledTimes(1);
const params = handleAction.mock.calls[0]?.[0]?.params as Record<string, unknown>;
expect(params.filename).toBe(path.basename(filePath));
expect(params.buffer).toBe(Buffer.from("hello").toString("base64"));
} finally {
await fs.unlink(filePath).catch(() => {});
}
});
it("allows send when target matches current channel", async () => {
const result = await runMessageAction({
cfg: slackConfig,
@@ -80,6 +152,21 @@ describe("runMessageAction context isolation", () => {
expect(result.kind).toBe("send");
});
it("defaults to current channel when target is omitted", async () => {
const result = await runMessageAction({
cfg: slackConfig,
action: "send",
params: {
channel: "slack",
message: "hi",
},
toolContext: { currentChannelId: "C12345678" },
dryRun: true,
});
expect(result.kind).toBe("send");
});
it("allows media-only send when target matches current channel", async () => {
const result = await runMessageAction({
cfg: slackConfig,
@@ -210,6 +297,33 @@ describe("runMessageAction context isolation", () => {
expect(result.kind).toBe("send");
});
it("infers channel + target from tool context when missing", async () => {
const multiConfig = {
channels: {
slack: {
botToken: "xoxb-test",
appToken: "xapp-test",
},
telegram: {
token: "tg-test",
},
},
} as ClawdbotConfig;
const result = await runMessageAction({
cfg: multiConfig,
action: "send",
params: {
message: "hi",
},
toolContext: { currentChannelId: "C12345678", currentChannelProvider: "slack" },
dryRun: true,
});
expect(result.kind).toBe("send");
expect(result.channel).toBe("slack");
});
it("blocks cross-provider sends by default", async () => {
await expect(
runMessageAction({
@@ -253,3 +367,91 @@ describe("runMessageAction context isolation", () => {
).rejects.toThrow(/Cross-context messaging denied/);
});
});
describe("runMessageAction sendAttachment hydration", () => {
const attachmentPlugin: ChannelPlugin = {
id: "bluebubbles",
meta: {
id: "bluebubbles",
label: "BlueBubbles",
selectionLabel: "BlueBubbles",
docsPath: "/channels/bluebubbles",
blurb: "BlueBubbles test plugin.",
},
capabilities: { chatTypes: ["direct"], media: true },
config: {
listAccountIds: () => ["default"],
resolveAccount: () => ({ enabled: true }),
isConfigured: () => true,
},
actions: {
listActions: () => ["sendAttachment"],
supportsAction: ({ action }) => action === "sendAttachment",
handleAction: async ({ params }) =>
jsonResult({
ok: true,
buffer: params.buffer,
filename: params.filename,
caption: params.caption,
contentType: params.contentType,
}),
},
};
beforeEach(() => {
setActivePluginRegistry(
createTestRegistry([
{
pluginId: "bluebubbles",
source: "test",
plugin: attachmentPlugin,
},
]),
);
vi.mocked(loadWebMedia).mockResolvedValue({
buffer: Buffer.from("hello"),
contentType: "image/png",
kind: "image",
fileName: "pic.png",
});
});
afterEach(() => {
setActivePluginRegistry(createTestRegistry([]));
vi.clearAllMocks();
});
it("hydrates buffer and filename from media for sendAttachment", async () => {
const cfg = {
channels: {
bluebubbles: {
enabled: true,
serverUrl: "http://localhost:1234",
password: "test-password",
},
},
} as ClawdbotConfig;
const result = await runMessageAction({
cfg,
action: "sendAttachment",
params: {
channel: "bluebubbles",
target: "+15551234567",
media: "https://example.com/pic.png",
message: "caption",
},
});
expect(result.kind).toBe("action");
expect(result.payload).toMatchObject({
ok: true,
filename: "pic.png",
caption: "caption",
contentType: "image/png",
});
expect((result.payload as { buffer?: string }).buffer).toBe(
Buffer.from("hello").toString("base64"),
);
});
});