import { getSlackClient, handleSlackError } from "../slack-client.js";
import type { SlackReaction } from "../types/slack.js";
export async function addReaction(
channelId: string,
timestamp: string,
emoji: string
): Promise<{ ok: true }> {
const client = getSlackClient();
try {
await client.reactions.add({
channel: channelId,
timestamp,
name: emoji.replace(/:/g, ""),
});
return { ok: true };
} catch (error) {
handleSlackError(error);
}
}
export async function removeReaction(
channelId: string,
timestamp: string,
emoji: string
): Promise<{ ok: true }> {
const client = getSlackClient();
try {
await client.reactions.remove({
channel: channelId,
timestamp,
name: emoji.replace(/:/g, ""),
});
return { ok: true };
} catch (error) {
handleSlackError(error);
}
}
export async function getReactions(
channelId: string,
timestamp: string
): Promise<{
reactions: SlackReaction[];
messageText: string;
}> {
const client = getSlackClient();
try {
const result = await client.reactions.get({
channel: channelId,
timestamp,
full: true,
});
const message = result.message as {
text?: string;
reactions?: Array<{ name: string; count: number; users: string[] }>;
};
return {
reactions: (message?.reactions || []).map((r) => ({
name: r.name,
count: r.count,
users: r.users,
})),
messageText: message?.text || "",
};
} catch (error) {
handleSlackError(error);
}
}
export const reactionToolDefinitions = [
{
name: "slack_add_reaction",
description: "Add an emoji reaction to a message",
inputSchema: {
type: "object" as const,
properties: {
channel_id: {
type: "string",
description: "The ID of the channel containing the message",
},
timestamp: {
type: "string",
description: "Timestamp of the message (e.g., 1234567890.123456)",
},
emoji: {
type: "string",
description: "Emoji name without colons (e.g., thumbsup, heart, rocket)",
},
},
required: ["channel_id", "timestamp", "emoji"],
},
},
{
name: "slack_remove_reaction",
description: "Remove an emoji reaction from a message",
inputSchema: {
type: "object" as const,
properties: {
channel_id: {
type: "string",
description: "The ID of the channel containing the message",
},
timestamp: {
type: "string",
description: "Timestamp of the message (e.g., 1234567890.123456)",
},
emoji: {
type: "string",
description: "Emoji name without colons (e.g., thumbsup, heart, rocket)",
},
},
required: ["channel_id", "timestamp", "emoji"],
},
},
{
name: "slack_get_reactions",
description: "Get all reactions on a specific message",
inputSchema: {
type: "object" as const,
properties: {
channel_id: {
type: "string",
description: "The ID of the channel containing the message",
},
timestamp: {
type: "string",
description: "Timestamp of the message (e.g., 1234567890.123456)",
},
},
required: ["channel_id", "timestamp"],
},
},
];