1 | |
2 |
|
3 | export type DynSelect_space = string |
4 |
|
5 | |
6 | export async function space(auth: RT.Gchat) { |
7 | const response = await fetch( |
8 | "https://chat.googleapis.com/v1/spaces?pageSize=1000", |
9 | { |
10 | headers: { |
11 | Authorization: `Bearer ${auth.token}`, |
12 | Accept: "application/json", |
13 | }, |
14 | } |
15 | ) |
16 | if (!response.ok) { |
17 | throw new Error(`${response.status} ${await response.text()}`) |
18 | } |
19 | const { spaces } = (await response.json()) as { |
20 | spaces?: { name: string; displayName?: string; spaceType: string }[] |
21 | } |
22 | return (spaces ?? []).map((s) => ({ |
23 | value: s.name, |
24 | label: s.displayName |
25 | ? `${s.displayName} (${s.name})` |
26 | : `${s.spaceType} ${s.name}`, |
27 | })) |
28 | } |
29 |
|
30 | |
31 | * Get Space |
32 | * Get a Chat space, group chat or DM: display name, type, threading state, history setting, member counts and URL. |
33 | */ |
34 | export async function main(auth: RT.Gchat, space: DynSelect_space) { |
35 | const response = await fetch(`https://chat.googleapis.com/v1/${space}`, { |
36 | headers: { |
37 | Authorization: `Bearer ${auth.token}`, |
38 | Accept: "application/json", |
39 | }, |
40 | }) |
41 | if (!response.ok) { |
42 | throw new Error(`${response.status} ${await response.text()}`) |
43 | } |
44 |
|
45 | return await response.json() |
46 | } |
47 |
|