mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-22 05:45:22 +02:00
feat: modify getChannels method to support fetching channels by IDs from env
This commit is contained in:
@@ -53,7 +53,7 @@ interface GetUserProfileArgs {
|
|||||||
// Tool definitions
|
// Tool definitions
|
||||||
const listChannelsTool: Tool = {
|
const listChannelsTool: Tool = {
|
||||||
name: "slack_list_channels",
|
name: "slack_list_channels",
|
||||||
description: "List public channels in the workspace with pagination",
|
description: "List public or pre-defined channels in the workspace with pagination",
|
||||||
inputSchema: {
|
inputSchema: {
|
||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
@@ -221,6 +221,8 @@ class SlackClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getChannels(limit: number = 100, cursor?: string): Promise<any> {
|
async getChannels(limit: number = 100, cursor?: string): Promise<any> {
|
||||||
|
const predefinedChannelIds = process.env.SLACK_CHANNEL_IDS;
|
||||||
|
if (!predefinedChannelIds) {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
types: "public_channel",
|
types: "public_channel",
|
||||||
exclude_archived: "true",
|
exclude_archived: "true",
|
||||||
@@ -240,6 +242,32 @@ class SlackClient {
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const predefinedChannelIdsArray = predefinedChannelIds.split(",").map((id: string) => id.trim());
|
||||||
|
const channels = [];
|
||||||
|
|
||||||
|
for (const channelId of predefinedChannelIdsArray) {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
channel: channelId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
`https://slack.com/api/conversations.info?${params}`,
|
||||||
|
{ headers: this.botHeaders }
|
||||||
|
);
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.ok && data.channel && !data.channel.is_archived) {
|
||||||
|
channels.push(data.channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
channels: channels,
|
||||||
|
response_metadata: { next_cursor: "" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async postMessage(channel_id: string, text: string): Promise<any> {
|
async postMessage(channel_id: string, text: string): Promise<any> {
|
||||||
const response = await fetch("https://slack.com/api/chat.postMessage", {
|
const response = await fetch("https://slack.com/api/chat.postMessage", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
Reference in New Issue
Block a user