//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}`,
}))
}
/**
* Get Space
* Get a Chat space, group chat or DM: display name, type, threading state, history setting, member counts and URL.
*/
export async function main(auth: RT.Gchat, space: DynSelect_space) {
const response = await fetch(`https://chat.googleapis.com/v1/${space}`, {
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