mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 09:22:45 +00:00
fix(outbound): unify resolved cfg threading across send paths (#33987)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import type { DiscordActionConfig } from "../../config/config.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { readDiscordComponentSpec } from "../../discord/components.js";
|
||||
import {
|
||||
createThreadDiscord,
|
||||
@@ -59,6 +60,7 @@ export async function handleDiscordMessagingAction(
|
||||
options?: {
|
||||
mediaLocalRoots?: readonly string[];
|
||||
},
|
||||
cfg?: OpenClawConfig,
|
||||
): Promise<AgentToolResult<unknown>> {
|
||||
const resolveChannelId = () =>
|
||||
resolveDiscordChannelId(
|
||||
@@ -67,6 +69,7 @@ export async function handleDiscordMessagingAction(
|
||||
}),
|
||||
);
|
||||
const accountId = readStringParam(params, "accountId");
|
||||
const cfgOptions = cfg ? { cfg } : {};
|
||||
const normalizeMessage = (message: unknown) => {
|
||||
if (!message || typeof message !== "object") {
|
||||
return message;
|
||||
@@ -90,22 +93,28 @@ export async function handleDiscordMessagingAction(
|
||||
});
|
||||
if (remove) {
|
||||
if (accountId) {
|
||||
await removeReactionDiscord(channelId, messageId, emoji, { accountId });
|
||||
await removeReactionDiscord(channelId, messageId, emoji, {
|
||||
...cfgOptions,
|
||||
accountId,
|
||||
});
|
||||
} else {
|
||||
await removeReactionDiscord(channelId, messageId, emoji);
|
||||
await removeReactionDiscord(channelId, messageId, emoji, cfgOptions);
|
||||
}
|
||||
return jsonResult({ ok: true, removed: emoji });
|
||||
}
|
||||
if (isEmpty) {
|
||||
const removed = accountId
|
||||
? await removeOwnReactionsDiscord(channelId, messageId, { accountId })
|
||||
: await removeOwnReactionsDiscord(channelId, messageId);
|
||||
? await removeOwnReactionsDiscord(channelId, messageId, { ...cfgOptions, accountId })
|
||||
: await removeOwnReactionsDiscord(channelId, messageId, cfgOptions);
|
||||
return jsonResult({ ok: true, removed: removed.removed });
|
||||
}
|
||||
if (accountId) {
|
||||
await reactMessageDiscord(channelId, messageId, emoji, { accountId });
|
||||
await reactMessageDiscord(channelId, messageId, emoji, {
|
||||
...cfgOptions,
|
||||
accountId,
|
||||
});
|
||||
} else {
|
||||
await reactMessageDiscord(channelId, messageId, emoji);
|
||||
await reactMessageDiscord(channelId, messageId, emoji, cfgOptions);
|
||||
}
|
||||
return jsonResult({ ok: true, added: emoji });
|
||||
}
|
||||
@@ -121,6 +130,7 @@ export async function handleDiscordMessagingAction(
|
||||
const limit =
|
||||
typeof limitRaw === "number" && Number.isFinite(limitRaw) ? limitRaw : undefined;
|
||||
const reactions = await fetchReactionsDiscord(channelId, messageId, {
|
||||
...cfgOptions,
|
||||
...(accountId ? { accountId } : {}),
|
||||
limit,
|
||||
});
|
||||
@@ -137,6 +147,7 @@ export async function handleDiscordMessagingAction(
|
||||
label: "stickerIds",
|
||||
});
|
||||
await sendStickerDiscord(to, stickerIds, {
|
||||
...cfgOptions,
|
||||
...(accountId ? { accountId } : {}),
|
||||
content,
|
||||
});
|
||||
@@ -165,7 +176,7 @@ export async function handleDiscordMessagingAction(
|
||||
await sendPollDiscord(
|
||||
to,
|
||||
{ question, options: answers, maxSelections, durationHours },
|
||||
{ ...(accountId ? { accountId } : {}), content },
|
||||
{ ...cfgOptions, ...(accountId ? { accountId } : {}), content },
|
||||
);
|
||||
return jsonResult({ ok: true });
|
||||
}
|
||||
@@ -276,6 +287,7 @@ export async function handleDiscordMessagingAction(
|
||||
? componentSpec
|
||||
: { ...componentSpec, text: normalizedContent };
|
||||
const result = await sendDiscordComponentMessage(to, payload, {
|
||||
...cfgOptions,
|
||||
...(accountId ? { accountId } : {}),
|
||||
silent,
|
||||
replyTo: replyTo ?? undefined,
|
||||
@@ -301,6 +313,7 @@ export async function handleDiscordMessagingAction(
|
||||
}
|
||||
assertMediaNotDataUrl(mediaUrl);
|
||||
const result = await sendVoiceMessageDiscord(to, mediaUrl, {
|
||||
...cfgOptions,
|
||||
...(accountId ? { accountId } : {}),
|
||||
replyTo,
|
||||
silent,
|
||||
@@ -309,6 +322,7 @@ export async function handleDiscordMessagingAction(
|
||||
}
|
||||
|
||||
const result = await sendMessageDiscord(to, content ?? "", {
|
||||
...cfgOptions,
|
||||
...(accountId ? { accountId } : {}),
|
||||
mediaUrl,
|
||||
mediaLocalRoots: options?.mediaLocalRoots,
|
||||
@@ -422,6 +436,7 @@ export async function handleDiscordMessagingAction(
|
||||
const mediaUrl = readStringParam(params, "mediaUrl");
|
||||
const replyTo = readStringParam(params, "replyTo");
|
||||
const result = await sendMessageDiscord(`channel:${channelId}`, content, {
|
||||
...cfgOptions,
|
||||
...(accountId ? { accountId } : {}),
|
||||
mediaUrl,
|
||||
mediaLocalRoots: options?.mediaLocalRoots,
|
||||
|
||||
@@ -107,7 +107,7 @@ describe("handleDiscordMessagingAction", () => {
|
||||
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅", expectedOptions);
|
||||
return;
|
||||
}
|
||||
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅");
|
||||
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅", {});
|
||||
});
|
||||
|
||||
it("removes reactions on empty emoji", async () => {
|
||||
@@ -120,7 +120,7 @@ describe("handleDiscordMessagingAction", () => {
|
||||
},
|
||||
enableAllActions,
|
||||
);
|
||||
expect(removeOwnReactionsDiscord).toHaveBeenCalledWith("C1", "M1");
|
||||
expect(removeOwnReactionsDiscord).toHaveBeenCalledWith("C1", "M1", {});
|
||||
});
|
||||
|
||||
it("removes reactions when remove flag set", async () => {
|
||||
@@ -134,7 +134,7 @@ describe("handleDiscordMessagingAction", () => {
|
||||
},
|
||||
enableAllActions,
|
||||
);
|
||||
expect(removeReactionDiscord).toHaveBeenCalledWith("C1", "M1", "✅");
|
||||
expect(removeReactionDiscord).toHaveBeenCalledWith("C1", "M1", "✅", {});
|
||||
});
|
||||
|
||||
it("rejects removes without emoji", async () => {
|
||||
|
||||
@@ -67,7 +67,7 @@ export async function handleDiscordAction(
|
||||
const isActionEnabled = createDiscordActionGate({ cfg, accountId });
|
||||
|
||||
if (messagingActions.has(action)) {
|
||||
return await handleDiscordMessagingAction(action, params, isActionEnabled, options);
|
||||
return await handleDiscordMessagingAction(action, params, isActionEnabled, options, cfg);
|
||||
}
|
||||
if (guildActions.has(action)) {
|
||||
return await handleDiscordGuildAction(action, params, isActionEnabled);
|
||||
|
||||
Reference in New Issue
Block a user