1 | |
2 | type Clickup = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Retrieve Channels |
7 | * This endpoint retrieves the Channels in a Workspace. |
8 | */ |
9 | export async function main( |
10 | auth: Clickup, |
11 | workspace_id: string, |
12 | description_format: "text/md" | "text/plain" | undefined, |
13 | cursor: string | undefined, |
14 | limit: string | undefined, |
15 | is_follower: string | undefined, |
16 | include_hidden: string | undefined, |
17 | with_comment_since: string | undefined, |
18 | room_types: string | undefined, |
19 | ) { |
20 | const url = new URL( |
21 | `https://api.clickup.com/api/v3/workspaces/${workspace_id}/chat/channels`, |
22 | ); |
23 | for (const [k, v] of [ |
24 | ["description_format", description_format], |
25 | ["cursor", cursor], |
26 | ["limit", limit], |
27 | ["is_follower", is_follower], |
28 | ["include_hidden", include_hidden], |
29 | ["with_comment_since", with_comment_since], |
30 | ["room_types", room_types], |
31 | ]) { |
32 | if (v !== undefined && v !== "" && k !== undefined) { |
33 | url.searchParams.append(k, v); |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: "GET", |
38 | headers: { |
39 | Authorization: auth.token, |
40 | }, |
41 | body: undefined, |
42 | }); |
43 | if (!response.ok) { |
44 | const text = await response.text(); |
45 | throw new Error(`${response.status} ${text}`); |
46 | } |
47 | return await response.json(); |
48 | } |
49 |
|