mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 04:30:24 +00:00
fix: unify upload-file message actions
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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 [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user