From 3224d1a75a76c5a02e2536a4141e043a3e0fd89b Mon Sep 17 00:00:00 2001 From: Marcus Castro Date: Tue, 10 Feb 2026 13:30:16 -0300 Subject: [PATCH] fix(slack): apply limit parameter to emoji-list action (#4293) --- src/agents/tools/slack-actions.e2e.test.ts | 22 +++++++++++++++++++++ src/agents/tools/slack-actions.ts | 23 +++++++++++++++++++--- src/channels/plugins/slack.actions.ts | 2 +- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/agents/tools/slack-actions.e2e.test.ts b/src/agents/tools/slack-actions.e2e.test.ts index 6ce3c8b9507..94c51815040 100644 --- a/src/agents/tools/slack-actions.e2e.test.ts +++ b/src/agents/tools/slack-actions.e2e.test.ts @@ -432,4 +432,26 @@ describe("handleSlackAction", () => { const [, , opts] = sendSlackMessage.mock.calls[0] ?? []; expect(opts?.token).toBe("xoxp-1"); }); + + it("returns all emojis when no limit is provided", async () => { + const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig; + const emojiMap = { wave: "url1", smile: "url2", heart: "url3" }; + listSlackEmojis.mockResolvedValueOnce({ ok: true, emoji: emojiMap }); + const result = await handleSlackAction({ action: "emojiList" }, cfg); + const payload = result.details as { ok: boolean; emojis: { emoji: Record } }; + expect(payload.ok).toBe(true); + expect(Object.keys(payload.emojis.emoji)).toHaveLength(3); + }); + + it("applies limit to emoji-list results", async () => { + const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig; + const emojiMap = { wave: "url1", smile: "url2", heart: "url3", fire: "url4", star: "url5" }; + listSlackEmojis.mockResolvedValueOnce({ ok: true, emoji: emojiMap }); + const result = await handleSlackAction({ action: "emojiList", limit: 2 }, cfg); + const payload = result.details as { ok: boolean; emojis: { emoji: Record } }; + expect(payload.ok).toBe(true); + const emojiKeys = Object.keys(payload.emojis.emoji); + expect(emojiKeys).toHaveLength(2); + expect(emojiKeys.every((k) => k in emojiMap)).toBe(true); + }); }); diff --git a/src/agents/tools/slack-actions.ts b/src/agents/tools/slack-actions.ts index e4de2472ad9..4fc7d410157 100644 --- a/src/agents/tools/slack-actions.ts +++ b/src/agents/tools/slack-actions.ts @@ -18,7 +18,13 @@ import { } from "../../slack/actions.js"; import { parseSlackTarget, resolveSlackChannelId } from "../../slack/targets.js"; import { withNormalizedTimestamp } from "../date-time.js"; -import { createActionGate, jsonResult, readReactionParams, readStringParam } from "./common.js"; +import { + createActionGate, + jsonResult, + readNumberParam, + readReactionParams, + readStringParam, +} from "./common.js"; const messagingActions = new Set(["sendMessage", "editMessage", "deleteMessage", "readMessages"]); @@ -305,8 +311,19 @@ export async function handleSlackAction( if (!isActionEnabled("emojiList")) { throw new Error("Slack emoji list is disabled."); } - const emojis = readOpts ? await listSlackEmojis(readOpts) : await listSlackEmojis(); - return jsonResult({ ok: true, emojis }); + const result = readOpts ? await listSlackEmojis(readOpts) : await listSlackEmojis(); + const ok = result.ok ?? false; + const limit = readNumberParam(params, "limit", { integer: true }); + if (limit != null && limit > 0 && result.emoji != null) { + const entries = Object.entries(result.emoji).toSorted(([a], [b]) => a.localeCompare(b)); + if (entries.length > limit) { + return jsonResult({ + ok, + emojis: { ...result, emoji: Object.fromEntries(entries.slice(0, limit)) }, + }); + } + } + return jsonResult({ ok, emojis: result }); } throw new Error(`Unknown action: ${action}`); diff --git a/src/channels/plugins/slack.actions.ts b/src/channels/plugins/slack.actions.ts index 60601f4fdf1..62fda7eb77b 100644 --- a/src/channels/plugins/slack.actions.ts +++ b/src/channels/plugins/slack.actions.ts @@ -211,7 +211,7 @@ export function createSlackActions(providerId: string): ChannelMessageActionAdap if (action === "emoji-list") { return await handleSlackAction( - { action: "emojiList", accountId: accountId ?? undefined }, + { action: "emojiList", limit: params.limit, accountId: accountId ?? undefined }, cfg, ); }