Method: spaces.setup
建立聊天室並新增指定使用者。呼叫使用者會自動加入聊天室,因此不應在要求中指定為成員。如需範例,請參閱「設定聊天室並邀請初始成員」。
如要指定要新增的人類成員,請使用適當的 membership.member.name
新增會員資格。如要新增人類使用者,請使用 users/{user}
,其中 {user}
可以是使用者的電子郵件地址。如果是同一個 Workspace 機構的使用者,{user}
也可以是 People API 中的 id
,或是 Directory API 中的 id
。舉例來說,如果 user@example.com
的 People API 使用者個人資料 ID 為 123456789
,您可以將 membership.member.name
設為 users/user@example.com
或 users/123456789
,將使用者加入聊天室。
如要指定要新增的 Google 群組,請使用適當的 membership.group_member.name
新增會員資格。如要新增或邀請 Google 群組,請使用 groups/{group}
,其中 {group}
是 Cloud Identity Groups API 中群組的 id
。舉例來說,您可以使用 Cloud Identity Groups Lookup API 擷取群組電子郵件 group@example.com
的 ID 123456789
,然後將 membership.group_member.name
設為 groups/123456789
,將群組加入空間。系統不支援群組電子郵件,而且 Google 群組只能新增為已命名聊天室的成員。
如果是名為聊天室或群組通訊,如果發起者封鎖或遭部分成員封鎖,或是沒有權限新增部分成員,則系統不會將這些成員加入已建立的聊天室。
如要建立呼叫使用者與其他使用者之間的即時訊息 (DM),請指定一個代表使用者的會員資格。如果使用者互相封鎖,要求就會失敗,系統也不會建立訊息。
如要在呼叫使用者和呼叫應用程式之間建立 DM,請將 Space.singleUserBotDm
設為 true
,且不指定任何會員資格。您只能使用這個方法,透過通話應用程式設定即時訊息。如要將通話應用程式新增為聊天室的成員,或新增兩位使用者之間的即時訊息,請參閱「邀請使用者或應用程式加入聊天室」。
如果兩位使用者之間已存在私訊,即使在使用者提出要求時,其中一方使用者封鎖對方,系統仍會傳回現有的私訊。
不支援含有分支回覆的聊天室。如果在設定聊天室時收到 ALREADY_EXISTS
錯誤訊息,請嘗試使用其他 displayName
。Google Workspace 機構內的現有聊天室可能已使用這個顯示名稱。
需要使用者驗證。
HTTP 要求
POST https://chat.googleapis.com/v1/spaces:setup
這個網址使用 gRPC 轉碼語法。
要求主體
要求主體的資料會採用以下結構:
JSON 表示法 |
{
"space": {
object (Space )
},
"requestId": string,
"memberships": [
{
object (Membership )
}
]
} |
欄位 |
space |
object (Space )
必要欄位。Space.spaceType 欄位為必填欄位。 如要建立聊天室,請將 Space.spaceType 設為 SPACE ,並設定 Space.displayName 。如果在設定聊天室時收到 ALREADY_EXISTS 錯誤訊息,請嘗試使用其他 displayName 。Google Workspace 機構內的現有聊天室可能已使用這個顯示名稱。 如要建立群組通訊,請將 Space.spaceType 設為 GROUP_CHAT 。請勿設定 Space.displayName 。 如要建立人與人之間的 1:1 對話,請將 Space.spaceType 設為 DIRECT_MESSAGE ,並將 Space.singleUserBotDm 設為 false 。請勿設定 Space.displayName 或 Space.spaceDetails 。 如要建立人與呼叫 Chat 應用程式之間的 1:1 對話,請將 Space.spaceType 設為 DIRECT_MESSAGE ,並將 Space.singleUserBotDm 設為 true 。請勿設定 Space.displayName 或 Space.spaceDetails 。 如果 DIRECT_MESSAGE 聊天室已存在,系統會傳回該聊天室,而不會建立新聊天室。
|
requestId |
string
選用設定。此要求的專屬 ID。建議使用隨機 UUID。指定現有要求 ID 會傳回使用該 ID 建立的聊天室,而不是建立新的聊天室。使用不同的已驗證使用者,指定相同 Chat 應用程式中的現有要求 ID 會傳回錯誤。
|
memberships[] |
object (Membership )
選用設定。邀請加入聊天室的 Google Chat 使用者或群組。請省略呼叫使用者,因為系統會自動加入該使用者。 目前,此集合允許的會員人數上限為 49 人 (除了呼叫端)。 針對人類會員,Membership.member 欄位必須包含 user ,並填入 name (格式:users/{user} ),且 type 設為 User.Type.HUMAN 。您只能在設定聊天室時新增使用者 (只有在透過通話應用程式設定即時訊息時,才能新增 Chat 應用程式)。您也可以使用使用者的電子郵件地址做為 {user} 的別名,新增成員。例如,user.name 可以是 users/example@gmail.com 。如要邀請 Gmail 使用者或外部 Google Workspace 網域的使用者,請務必使用使用者的電子郵件地址建立 {user} 。 針對 Google 群組會員資格,Membership.group_member 欄位必須包含已填入 name 的 group (格式為 groups/{group} )。您只能在將 Space.spaceType 設為 SPACE 時新增 Google 群組。 將 Space.spaceType 設為 SPACE 時為選填。 將 Space.spaceType 設為 GROUP_CHAT 時必須使用,且至少須有兩個會員資格。 當您將 Space.spaceType 設為 DIRECT_MESSAGE 並與真人使用者互動時,此屬性為必要屬性,且必須搭配單一會員資格。 在建立人與呼叫 Chat 應用程式之間的 1:1 對話時,必須為空白 (將 Space.spaceType 設為 DIRECT_MESSAGE ,並將 Space.singleUserBotDm 設為 true )。
|
回應主體
如果成功,回應主體會包含 Space
的執行例項。
授權範圍
需要下列其中一種 OAuth 範圍:
https://www.googleapis.com/auth/chat.spaces
https://www.googleapis.com/auth/chat.spaces.create
詳情請參閱授權指南。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-02-27 (世界標準時間)。
[null,null,["上次更新時間:2025-02-27 (世界標準時間)。"],[[["Creates a new space in Google Chat and adds specified users or Google Groups."],["Supports creating spaces, group chats, and direct messages (DMs), including DMs with the calling app."],["Requires specifying the space type, display name (for spaces only), and memberships for users or groups to be added."],["Automatically adds the calling user to the space and does not support adding Chat apps except in DMs with the calling app."],["Requires user authentication with specific OAuth scopes for authorization."]]],["This content describes how to create spaces and add members in Google Chat. Key actions include: sending a `POST` request to `https://chat.googleapis.com/v1/spaces:setup` with a request body containing a `space` object (specifying space type and details), an optional `requestId`, and an array of `memberships` to define users or groups to invite. Users are identified by their email or ID, and groups by their ID. Different `spaceType` are used to create a space, a group chat or a direct message. Authorization requires specific OAuth scopes.\n"]]