mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 21:28:26 +00:00
refactor(outbound): dedupe attachment hydration
This commit is contained in:
@@ -272,6 +272,42 @@ export async function normalizeSandboxMediaList(params: {
|
|||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function hydrateAttachmentActionPayload(params: {
|
||||||
|
cfg: OpenClawConfig;
|
||||||
|
channel: ChannelId;
|
||||||
|
accountId?: string | null;
|
||||||
|
args: Record<string, unknown>;
|
||||||
|
dryRun?: boolean;
|
||||||
|
/** If caption is missing, copy message -> caption. */
|
||||||
|
allowMessageCaptionFallback?: boolean;
|
||||||
|
}): Promise<void> {
|
||||||
|
const mediaHint = readStringParam(params.args, "media", { trim: false });
|
||||||
|
const fileHint =
|
||||||
|
readStringParam(params.args, "path", { trim: false }) ??
|
||||||
|
readStringParam(params.args, "filePath", { trim: false });
|
||||||
|
const contentTypeParam =
|
||||||
|
readStringParam(params.args, "contentType") ?? readStringParam(params.args, "mimeType");
|
||||||
|
|
||||||
|
if (params.allowMessageCaptionFallback) {
|
||||||
|
const caption = readStringParam(params.args, "caption", { allowEmpty: true })?.trim();
|
||||||
|
const message = readStringParam(params.args, "message", { allowEmpty: true })?.trim();
|
||||||
|
if (!caption && message) {
|
||||||
|
params.args.caption = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await hydrateAttachmentPayload({
|
||||||
|
cfg: params.cfg,
|
||||||
|
channel: params.channel,
|
||||||
|
accountId: params.accountId,
|
||||||
|
args: params.args,
|
||||||
|
dryRun: params.dryRun,
|
||||||
|
contentTypeParam,
|
||||||
|
mediaHint,
|
||||||
|
fileHint,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function hydrateSetGroupIconParams(params: {
|
export async function hydrateSetGroupIconParams(params: {
|
||||||
cfg: OpenClawConfig;
|
cfg: OpenClawConfig;
|
||||||
channel: ChannelId;
|
channel: ChannelId;
|
||||||
@@ -283,23 +319,7 @@ export async function hydrateSetGroupIconParams(params: {
|
|||||||
if (params.action !== "setGroupIcon") {
|
if (params.action !== "setGroupIcon") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await hydrateAttachmentActionPayload(params);
|
||||||
const mediaHint = readStringParam(params.args, "media", { trim: false });
|
|
||||||
const fileHint =
|
|
||||||
readStringParam(params.args, "path", { trim: false }) ??
|
|
||||||
readStringParam(params.args, "filePath", { trim: false });
|
|
||||||
const contentTypeParam =
|
|
||||||
readStringParam(params.args, "contentType") ?? readStringParam(params.args, "mimeType");
|
|
||||||
await hydrateAttachmentPayload({
|
|
||||||
cfg: params.cfg,
|
|
||||||
channel: params.channel,
|
|
||||||
accountId: params.accountId,
|
|
||||||
args: params.args,
|
|
||||||
dryRun: params.dryRun,
|
|
||||||
contentTypeParam,
|
|
||||||
mediaHint,
|
|
||||||
fileHint,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function hydrateSendAttachmentParams(params: {
|
export async function hydrateSendAttachmentParams(params: {
|
||||||
@@ -313,28 +333,7 @@ export async function hydrateSendAttachmentParams(params: {
|
|||||||
if (params.action !== "sendAttachment") {
|
if (params.action !== "sendAttachment") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await hydrateAttachmentActionPayload({ ...params, allowMessageCaptionFallback: true });
|
||||||
const mediaHint = readStringParam(params.args, "media", { trim: false });
|
|
||||||
const fileHint =
|
|
||||||
readStringParam(params.args, "path", { trim: false }) ??
|
|
||||||
readStringParam(params.args, "filePath", { trim: false });
|
|
||||||
const contentTypeParam =
|
|
||||||
readStringParam(params.args, "contentType") ?? readStringParam(params.args, "mimeType");
|
|
||||||
const caption = readStringParam(params.args, "caption", { allowEmpty: true })?.trim();
|
|
||||||
const message = readStringParam(params.args, "message", { allowEmpty: true })?.trim();
|
|
||||||
if (!caption && message) {
|
|
||||||
params.args.caption = message;
|
|
||||||
}
|
|
||||||
await hydrateAttachmentPayload({
|
|
||||||
cfg: params.cfg,
|
|
||||||
channel: params.channel,
|
|
||||||
accountId: params.accountId,
|
|
||||||
args: params.args,
|
|
||||||
dryRun: params.dryRun,
|
|
||||||
contentTypeParam,
|
|
||||||
mediaHint,
|
|
||||||
fileHint,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseButtonsParam(params: Record<string, unknown>): void {
|
export function parseButtonsParam(params: Record<string, unknown>): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user