list-channels.usecase.tsā¢1.56 kB
import { ISlackService } from "../../core/interfaces/slack.interface.js";
import { ListChannelsRequest } from "../../core/types/slack.types.js";
export class ListChannelsUseCase {
constructor(private readonly slackService: ISlackService) {}
async execute(request: ListChannelsRequest) {
const result = await this.slackService.listChannels(request);
if (!result.success) {
return {
content: [
{
type: "text" as const,
text: `ā Failed to list channels: ${result.error}`,
},
],
};
}
const { channels, next_cursor } = result.data!;
if (channels.length === 0) {
return {
content: [
{
type: "text" as const,
text: "š No channels found.",
},
],
};
}
const channelList = channels
.map((channel, index) => {
const memberCount = channel.num_members
? ` (${channel.num_members} members)`
: "";
const isPrivate = channel.is_private ? " š" : "";
return `${index + 1}. **#${
channel.name
}**${isPrivate}${memberCount}\n ID: \`${channel.id}\``;
})
.join("\n\n");
const paginationInfo = next_cursor
? `\n\nš **Pagination**: Use cursor \`${next_cursor}\` for next page`
: "";
return {
content: [
{
type: "text" as const,
text: `š **Slack Channels** (${channels.length} found)\n\n${channelList}${paginationInfo}`,
},
],
};
}
}