Edits history of script submission #23309 for ' Get Space (gchat)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //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