0

Create Channel

by
Published today

Create a public or private channel. Requires channels:manage (bot) or channels:write (user); private channels need groups:write.

Script slack Verified

The script

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

3
/**
4
 * Create Channel
5
 * Create a public or private channel. `name` must be lowercase, without spaces or periods, and at most 80 characters. Requires channels:manage (bot token) or channels:write (user token) on the connection; a private channel needs groups:write instead.
6
 */
7
export async function main(auth: RT.Slack, name: string, is_private?: boolean) {
8
  const client = new WebClient(auth.token)
9
  return await client.conversations.create(dropEmpty({ name, is_private }))
10
}
11

12
function dropEmpty<T extends { [key: string]: any }>(params: T) {
13
  return Object.fromEntries(
14
    Object.entries(params).filter(
15
      ([, v]) => v !== undefined && v !== null && v !== ""
16
    )
17
  ) as T
18
}
19