(
options: { types?: string; exclude_archived?: boolean } = {}
)
| 636 | * Get all channels in the workspace (public channels only by default) |
| 637 | */ |
| 638 | export async function getSlackChannels( |
| 639 | options: { types?: string; exclude_archived?: boolean } = {} |
| 640 | ): Promise<SlackChannel[]> { |
| 641 | const channels: SlackChannel[] = []; |
| 642 | let cursor: string | undefined; |
| 643 | |
| 644 | do { |
| 645 | const response = await slackRequest<SlackPaginatedResponse<SlackChannel>>( |
| 646 | 'conversations.list', |
| 647 | { |
| 648 | types: options.types || 'public_channel', |
| 649 | exclude_archived: options.exclude_archived ?? true, |
| 650 | limit: 200, |
| 651 | cursor, |
| 652 | } |
| 653 | ); |
| 654 | |
| 655 | if (response.channels) { |
| 656 | channels.push(...response.channels); |
| 657 | } |
| 658 | |
| 659 | cursor = response.response_metadata?.next_cursor; |
| 660 | |
| 661 | if (cursor) { |
| 662 | await sleep(RATE_LIMIT_DELAY_MS); |
| 663 | } |
| 664 | } while (cursor); |
| 665 | |
| 666 | logger.info({ count: channels.length }, 'Fetched Slack channels'); |
| 667 | return channels; |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Get channel info by ID (cached for 30 minutes) |
no test coverage detected