(channelId: string)
| 671 | * Get channel info by ID (cached for 30 minutes) |
| 672 | */ |
| 673 | export async function getChannelInfo(channelId: string): Promise<SlackChannel | null> { |
| 674 | const now = Date.now(); |
| 675 | |
| 676 | // Check cache |
| 677 | const cached = channelCache.get(channelId); |
| 678 | if (cached && cached.expiresAt > now) { |
| 679 | return cached.channel; |
| 680 | } |
| 681 | |
| 682 | try { |
| 683 | const response = await slackRequest<{ channel: SlackChannel }>('conversations.info', { |
| 684 | channel: channelId, |
| 685 | }); |
| 686 | |
| 687 | // Evict oldest entry if cache is full |
| 688 | if (channelCache.size >= MAX_CHANNEL_CACHE_SIZE) { |
| 689 | const oldestKey = channelCache.keys().next().value; |
| 690 | if (oldestKey) { |
| 691 | channelCache.delete(oldestKey); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | // Cache the result |
| 696 | channelCache.set(channelId, { |
| 697 | channel: response.channel, |
| 698 | expiresAt: now + CHANNEL_CACHE_TTL_MS, |
| 699 | }); |
| 700 | |
| 701 | return response.channel; |
| 702 | } catch (error) { |
| 703 | const safeId = channelId.replace(/[^A-Za-z0-9]/g, ''); |
| 704 | logger.warn({ error, channelId }, `Failed to get channel info for ${safeId}`); |
| 705 | return null; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * Get members of a channel |
no test coverage detected