import { getSlackClient, handleSlackError } from "../slack-client.js";
import type { SlackChannel } from "../types/slack.js";
export async function listChannels(options?: {
types?: string;
excludeArchived?: boolean;
limit?: number;
cursor?: string;
}): Promise<{
channels: SlackChannel[];
nextCursor?: string;
}> {
const client = getSlackClient();
try {
const result = await client.conversations.list({
types: options?.types || "public_channel,private_channel",
exclude_archived: options?.excludeArchived ?? true,
limit: options?.limit || 100,
cursor: options?.cursor,
});
const channels: SlackChannel[] = (result.channels || []).map((ch) => ({
id: ch.id!,
name: ch.name || "",
is_private: ch.is_private || false,
is_archived: ch.is_archived || false,
topic: ch.topic?.value,
purpose: ch.purpose?.value,
member_count: ch.num_members,
created: ch.created,
}));
return {
channels,
nextCursor: result.response_metadata?.next_cursor || undefined,
};
} catch (error) {
handleSlackError(error);
}
}
export async function getChannelInfo(channelId: string): Promise<SlackChannel> {
const client = getSlackClient();
try {
const result = await client.conversations.info({
channel: channelId,
include_num_members: true,
});
const ch = result.channel!;
return {
id: ch.id!,
name: ch.name || "",
is_private: ch.is_private || false,
is_archived: ch.is_archived || false,
topic: ch.topic?.value,
purpose: ch.purpose?.value,
member_count: ch.num_members,
created: ch.created,
};
} catch (error) {
handleSlackError(error);
}
}
export async function getChannelMembers(
channelId: string,
options?: {
limit?: number;
cursor?: string;
}
): Promise<{
members: string[];
nextCursor?: string;
}> {
const client = getSlackClient();
try {
const result = await client.conversations.members({
channel: channelId,
limit: options?.limit || 100,
cursor: options?.cursor,
});
return {
members: result.members || [],
nextCursor: result.response_metadata?.next_cursor || undefined,
};
} catch (error) {
handleSlackError(error);
}
}
export const channelToolDefinitions = [
{
name: "slack_list_channels",
description:
"List all Slack channels (public and private) accessible to the user",
inputSchema: {
type: "object" as const,
properties: {
types: {
type: "string",
description:
"Comma-separated channel types: public_channel, private_channel, mpim, im",
default: "public_channel,private_channel",
},
exclude_archived: {
type: "boolean",
description: "Exclude archived channels",
default: true,
},
limit: {
type: "number",
description: "Maximum number of channels to return (max 1000)",
default: 100,
},
cursor: {
type: "string",
description: "Pagination cursor for next page",
},
},
required: [],
},
},
{
name: "slack_get_channel_info",
description: "Get detailed information about a specific Slack channel",
inputSchema: {
type: "object" as const,
properties: {
channel_id: {
type: "string",
description: "The ID of the channel (e.g., C1234567890)",
},
},
required: ["channel_id"],
},
},
{
name: "slack_get_channel_members",
description: "Get the list of members in a Slack channel",
inputSchema: {
type: "object" as const,
properties: {
channel_id: {
type: "string",
description: "The ID of the channel (e.g., C1234567890)",
},
limit: {
type: "number",
description: "Maximum number of members to return (max 1000)",
default: 100,
},
cursor: {
type: "string",
description: "Pagination cursor for next page",
},
},
required: ["channel_id"],
},
},
];