@@ -53,7 +53,7 @@ interface GetUserProfileArgs {
5353// Tool definitions
5454const listChannelsTool : Tool = {
5555 name : "slack_list_channels" ,
56- description : "List public channels in the workspace with pagination" ,
56+ description : "List public or pre-defined channels in the workspace with pagination" ,
5757 inputSchema : {
5858 type : "object" ,
5959 properties : {
@@ -221,23 +221,51 @@ class SlackClient {
221221 }
222222
223223 async getChannels ( limit : number = 100 , cursor ?: string) : Promise < any > {
224- const params = new URLSearchParams ( {
225- types : "public_channel" ,
226- exclude_archived : "true" ,
227- limit : Math . min ( limit , 200 ) . toString ( ) ,
228- team_id : process . env . SLACK_TEAM_ID ! ,
229- } ) ;
230-
231- if ( cursor ) {
232- params . append ( "cursor" , cursor ) ;
224+ const predefinedChannelIds = process . env . SLACK_CHANNEL_IDS ;
225+ if ( ! predefinedChannelIds ) {
226+ const params = new URLSearchParams ( {
227+ types : "public_channel" ,
228+ exclude_archived : "true" ,
229+ limit : Math . min ( limit , 200 ) . toString ( ) ,
230+ team_id : process . env . SLACK_TEAM_ID ! ,
231+ } ) ;
232+
233+ if ( cursor ) {
234+ params . append ( "cursor" , cursor ) ;
235+ }
236+
237+ const response = await fetch (
238+ `https://slack.com/api/conversations.list?${ params } ` ,
239+ { headers : this . botHeaders } ,
240+ ) ;
241+
242+ return response . json ( ) ;
233243 }
234244
235- const response = await fetch (
236- `https://slack.com/api/conversations.list?${ params } ` ,
237- { headers : this . botHeaders } ,
238- ) ;
245+ const predefinedChannelIdsArray = predefinedChannelIds . split ( "," ) . map ( ( id : string ) => id . trim ( ) ) ;
246+ const channels = [ ] ;
239247
240- return response . json ( ) ;
248+ for ( const channelId of predefinedChannelIdsArray ) {
249+ const params = new URLSearchParams ( {
250+ channel : channelId ,
251+ } ) ;
252+
253+ const response = await fetch (
254+ `https://slack.com/api/conversations.info?${ params } ` ,
255+ { headers : this . botHeaders }
256+ ) ;
257+ const data = await response . json ( ) ;
258+
259+ if ( data . ok && data . channel && ! data . channel . is_archived ) {
260+ channels . push ( data . channel ) ;
261+ }
262+ }
263+
264+ return {
265+ ok : true ,
266+ channels : channels ,
267+ response_metadata : { next_cursor : "" } ,
268+ } ;
241269 }
242270
243271 async postMessage ( channel_id : string , text : string) : Promise < any > {
0 commit comments