fix: unify upload-file message actions

This commit is contained in:
Peter Steinberger
2026-03-27 01:00:06 +00:00
parent 046a950877
commit ba60154826
13 changed files with 333 additions and 27 deletions

View File

@@ -297,7 +297,13 @@ export async function hydrateAttachmentParamsForAction(params: {
dryRun?: boolean;
mediaPolicy: AttachmentMediaPolicy;
}): Promise<void> {
if (params.action !== "sendAttachment" && params.action !== "setGroupIcon") {
const shouldHydrateBlueBubblesUploadFile =
params.action === "upload-file" && params.channel === "bluebubbles";
if (
params.action !== "sendAttachment" &&
params.action !== "setGroupIcon" &&
!shouldHydrateBlueBubblesUploadFile
) {
return;
}
await hydrateAttachmentActionPayload({
@@ -307,7 +313,8 @@ export async function hydrateAttachmentParamsForAction(params: {
args: params.args,
dryRun: params.dryRun,
mediaPolicy: params.mediaPolicy,
allowMessageCaptionFallback: params.action === "sendAttachment",
allowMessageCaptionFallback:
params.action === "sendAttachment" || shouldHydrateBlueBubblesUploadFile,
});
}

View File

@@ -155,8 +155,9 @@ describe("runMessageAction media behavior", () => {
isConfigured: () => true,
},
actions: {
describeMessageTool: () => ({ actions: ["sendAttachment", "setGroupIcon"] }),
supportsAction: ({ action }) => action === "sendAttachment" || action === "setGroupIcon",
describeMessageTool: () => ({ actions: ["sendAttachment", "upload-file", "setGroupIcon"] }),
supportsAction: ({ action }) =>
action === "sendAttachment" || action === "upload-file" || action === "setGroupIcon",
handleAction: async ({ params }) =>
jsonResult({
ok: true,
@@ -267,6 +268,30 @@ describe("runMessageAction media behavior", () => {
);
});
it("hydrates buffer and filename from media for bluebubbles upload-file", async () => {
const result = await runMessageAction({
cfg,
action: "upload-file",
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"),
);
});
it("enforces sandboxed attachment paths for attachment actions", async () => {
for (const testCase of [
{