import { WebClient } from "@slack/web-api"
export type DynSelect_channel = string
// Dropdown of channels the token can see; private channels need groups:read.
export async function channel(auth: RT.Slack) {
if (!auth?.token) return []
const client = new WebClient(auth.token)
const res = await client.conversations
.list({
types: "public_channel,private_channel",
exclude_archived: true,
limit: 1000,
})
.catch(() =>
client.conversations.list({ exclude_archived: true, limit: 1000 })
)
return (res.channels ?? []).map((c) => ({
value: c.id!,
label: `#${c.name}`,
}))
}
/**
* Get Channel Details
* Get a conversation's details — name, topic, purpose, creator, archived flag — by ID. Set `include_num_members` for the member count. Needs channels:read (groups:read for private channels, im:read / mpim:read for DMs).
*/
export async function main(
auth: RT.Slack,
channel: DynSelect_channel,
include_num_members?: boolean
) {
const client = new WebClient(auth.token)
return await client.conversations.info(
dropEmpty({ channel, include_num_members })
)
}
function dropEmpty<T extends { [key: string]: any }>(params: T) {
return Object.fromEntries(
Object.entries(params).filter(
([, v]) => v !== undefined && v !== null && v !== ""
)
) as T
}
Submitted by hugo989 2 hours ago