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}`,
}))
}
/**
* List Members in Channel
* List the user IDs in a conversation (resolve them with Get User). Page with `cursor` = the previous `response_metadata.next_cursor`. Needs channels:read (groups:read for private channels, im:read / mpim:read for DMs).
*/
export async function main(
auth: RT.Slack,
channel: DynSelect_channel,
limit?: number,
cursor?: string
) {
const client = new WebClient(auth.token)
return await client.conversations.members(
dropEmpty({ channel, limit, cursor })
)
}
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