0

List Spaces

by
Published today

List the Google Chat spaces, group chats and DMs the user is a member of.

Script gchat Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * List Spaces
5
 * List the Chat spaces, group chats and direct messages the connected user is a member of. Each item's `spaceType` is SPACE, GROUP_CHAT or DIRECT_MESSAGE. Pass the returned `nextPageToken` as `page_token` for the next page.
6
 */
7
export async function main(
8
  auth: RT.Gchat,
9
  page_size: number = 100,
10
  page_token: string | undefined
11
) {
12
  const url = new URL("https://chat.googleapis.com/v1/spaces")
13
  url.searchParams.append("pageSize", String(page_size))
14
  if (page_token !== undefined && page_token !== "")
15
    url.searchParams.append("pageToken", page_token)
16

17
  const response = await fetch(url, {
18
    headers: {
19
      Authorization: `Bearer ${auth.token}`,
20
      Accept: "application/json",
21
    },
22
  })
23
  if (!response.ok) {
24
    throw new Error(`${response.status} ${await response.text()}`)
25
  }
26

27
  return await response.json()
28
}
29