mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 08:57:40 +00:00
fix(channels): normalize MIME kind parsing and reaction fallbacks
This commit is contained in:
@@ -456,6 +456,43 @@ describe("handleDiscordMessageAction", () => {
|
||||
expect.objectContaining({ mediaLocalRoots: ["/tmp/agent-root"] }),
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to toolContext.currentMessageId for reactions when messageId is omitted", async () => {
|
||||
await handleDiscordMessageAction({
|
||||
action: "react",
|
||||
params: {
|
||||
channelId: "123",
|
||||
emoji: "ok",
|
||||
},
|
||||
cfg: {} as OpenClawConfig,
|
||||
toolContext: { currentMessageId: "9001" },
|
||||
});
|
||||
|
||||
const call = handleDiscordAction.mock.calls.at(-1);
|
||||
expect(call?.[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
action: "react",
|
||||
channelId: "123",
|
||||
messageId: "9001",
|
||||
emoji: "ok",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects reactions when neither messageId nor toolContext.currentMessageId is provided", async () => {
|
||||
await expect(
|
||||
handleDiscordMessageAction({
|
||||
action: "react",
|
||||
params: {
|
||||
channelId: "123",
|
||||
emoji: "ok",
|
||||
},
|
||||
cfg: {} as OpenClawConfig,
|
||||
}),
|
||||
).rejects.toThrow(/messageId required/i);
|
||||
|
||||
expect(handleDiscordAction).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("telegramMessageActions", () => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { readDiscordParentIdParam } from "../../../../agents/tools/discord-actio
|
||||
import { handleDiscordAction } from "../../../../agents/tools/discord-actions.js";
|
||||
import { resolveDiscordChannelId } from "../../../../discord/targets.js";
|
||||
import type { ChannelMessageActionContext } from "../../types.js";
|
||||
import { resolveReactionMessageId } from "../reaction-message-id.js";
|
||||
import { tryHandleDiscordMessageActionGuildAdmin } from "./handle-action.guild-admin.js";
|
||||
|
||||
const providerId = "discord";
|
||||
@@ -107,7 +108,13 @@ export async function handleDiscordMessageAction(
|
||||
}
|
||||
|
||||
if (action === "react") {
|
||||
const messageId = readStringParam(params, "messageId", { required: true });
|
||||
const messageIdRaw = resolveReactionMessageId({ args: params, toolContext: ctx.toolContext });
|
||||
const messageId = messageIdRaw != null ? String(messageIdRaw).trim() : "";
|
||||
if (!messageId) {
|
||||
throw new Error(
|
||||
"messageId required. Provide messageId explicitly or react to the current inbound message.",
|
||||
);
|
||||
}
|
||||
const emoji = readStringParam(params, "emoji", { allowEmpty: true });
|
||||
const remove = typeof params.remove === "boolean" ? params.remove : undefined;
|
||||
return await handleDiscordAction(
|
||||
|
||||
Reference in New Issue
Block a user