//native
export type DynSelect_space = string
// Dropdown of the spaces, group chats and DMs the user is a member of.
export async function space(auth: RT.Gchat) {
const response = await fetch(
"https://chat.googleapis.com/v1/spaces?pageSize=1000",
{
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { spaces } = (await response.json()) as {
spaces?: { name: string; displayName?: string; spaceType: string }[]
}
return (spaces ?? []).map((s) => ({
value: s.name,
label: s.displayName
? `${s.displayName} (${s.name})`
: `${s.spaceType} ${s.name}`,
}))
}
/**
* List Members
* List the members of a Chat space (human users by default; set `show_groups` to include Google Groups and `show_invited` to include pending invites). `filter` narrows by role or type, e.g. `role = "ROLE_MANAGER"` or `member.type = "HUMAN"`. Pass the returned `nextPageToken` as `page_token` for the next page. Members' `member.displayName` is only filled for the user's own entry. Requires chat.memberships.readonly on the connection (not in the default scopes).
*/
export async function main(
auth: RT.Gchat,
space: DynSelect_space,
filter: string | undefined,
show_groups: boolean = false,
show_invited: boolean = false,
page_size: number = 100,
page_token: string | undefined
) {
const url = new URL(`https://chat.googleapis.com/v1/${space}/members`)
url.searchParams.append("pageSize", String(page_size || 100))
url.searchParams.append("showGroups", String(!!show_groups))
url.searchParams.append("showInvited", String(!!show_invited))
if (filter != null && filter !== "")
url.searchParams.append("filter", filter)
if (page_token != null && page_token !== "")
url.searchParams.append("pageToken", page_token)
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 6 hours ago