0

List User Groups

by
Published today

List the workspace's user groups, optionally with their members.

Script slack Verified

The script

Submitted by hugo989 Bun
Verified 1 hour ago
1
import { WebClient } from "@slack/web-api"
2

3
/**
4
 * List User Groups
5
 * List the workspace's user groups (e.g. @oncall) with their IDs and handles; `include_users` adds each group's member IDs, `include_disabled` adds disabled groups. Requires usergroups:read on the connection.
6
 */
7
export async function main(
8
  auth: RT.Slack,
9
  include_users?: boolean,
10
  include_disabled?: boolean,
11
  include_count?: boolean
12
) {
13
  const client = new WebClient(auth.token)
14
  return await client.usergroups.list(
15
    dropEmpty({ include_users, include_disabled, include_count })
16
  )
17
}
18

19
function dropEmpty<T extends { [key: string]: any }>(params: T) {
20
  return Object.fromEntries(
21
    Object.entries(params).filter(
22
      ([, v]) => v !== undefined && v !== null && v !== ""
23
    )
24
  ) as T
25
}
26