提供意見
訂閱 Google Chat 活動
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁說明 Google Chat 應用程式可使用 Google Workspace Events API 訂閱的 Google Chat 事件。決定所需的事件類型後,請建立訂閱項目 ,開始接收 Google Chat 的事件。
除了訂閱事件外,您也可以呼叫 Chat API 來查詢事件。呼叫 Chat API 可讓您定期擷取事件,或追蹤因服務中斷而錯過的訂閱事件。如要瞭解如何接收及回應 Chat 事件,請參閱 Chat 說明文件中的「使用 Google Chat 事件 」一文。
支援的即時通訊事件
訂閱 Google Workspace 後,您就能接收 Chat 中下列類型的變更事件:
聊天室中的新訊息、更新訊息或已刪除的訊息 。
訊息的回應 (新增或移除)。
聊天室中的新、更新或移除的成員 。
你訂閱的聊天室 有變更,例如更新聊天室名稱或說明。
可監控事件的資源
如要接收事件,您必須指定要監控的 Chat 資源,這稱為訂閱的目標資源 。
Google Workspace Events API 支援以下 Chat 目標資源:
目標資源
格式
限制
空格
//chat.googleapis.com/spaces/SPACE
其中 SPACE 是 Chat API space
資源的
資源名稱 中的 ID。您可以從聊天室的網址取得 ID,也可以使用
spaces.list()
方法。
授權訂閱的 Chat 使用者必須透過 Google Workspace 或 Google 帳戶成為聊天室的成員。
使用者的所有聊天室
//chat.googleapis.com/spaces/-
訂閱項目只會接收使用者透過 Google Workspace 或 Google 帳戶成為成員的聊天室活動。
使用者
//cloudidentity.googleapis.com/users/USER
其中 USER 是 Chat API user
資源的
資源名稱 中的 ID。詳情請參閱「找出並指定 Google Chat 使用者 」。
訂閱項目只會收到授權訂閱的使用者相關事件。使用者無法代表其他使用者授權訂閱。
建立訂閱項目的事件類型
建立訂閱時,您可以使用 eventTypes[]
欄位指定要接收哪些類型的事件。事件類型會依照 CloudEvents 規格設定格式,例如 google.workspace.APPLICATION .RESOURCE .VERSION .ACTION
。
舉例來說,如要接收有關使用者加入 Chat 聊天室的事件,請將聊天室指定為目標資源,並將事件類型設為 google.workspace.chat.membership.v1.created
。如要接收關於特定使用者加入任何聊天室的事件,請將使用者指定為目標資源,並將事件類型指定為 google.workspace.chat.membership.v1.created
。如要進一步瞭解事件的運作方式,請參閱「Google Workspace 事件結構 」。
下表列出支援的空間訂閱和使用者訂閱事件類型。如要瞭解觸發事件的例外狀況,請參閱「限制 」一節。
事件類型
格式
資源資料
訂閱聊天室
已張貼訊息。
google.workspace.chat.message.v1.created
space.message
訊息已更新。
google.workspace.chat.message.v1.updated
space.message
訊息已刪除。
google.workspace.chat.message.v1.deleted
space.message
建立反應。
google.workspace.chat.reaction.v1.created
space.message.reaction
已刪除回應。
google.workspace.chat.reaction.v1.deleted
space.message.reaction
將成員新增至聊天室。
google.workspace.chat.membership.v1.created
space.membership
聊天室中的成員已更新。
google.workspace.chat.membership.v1.updated
space.membership
將成員從聊天室中移除。
google.workspace.chat.membership.v1.deleted
space.membership
聊天室已更新。
google.workspace.chat.space.v1.updated
space
聊天室已刪除。
google.workspace.chat.space.v1.deleted
space
使用者訂閱
使用者成為聊天室成員。
並非所有新會員都會觸發事件。詳情請參閱「限制 」一節
google.workspace.chat.membership.v1.created
space.membership
使用者在聊天室的會員資格已更新。
google.workspace.chat.membership.v1.updated
space.membership
使用者會從聊天室的直接成員名單中移除。
google.workspace.chat.membership.v1.deleted
space.membership
批次事件類型 (僅限輸出)
除了接收您訂閱的事件類型外,Chat 應用程式也可能會接收批次事件。批次事件是指在短時間內發生的多個同類型事件。批次事件的酬載包含所有已變更資源的清單。
舉例來說,如果使用者同時將 20 位使用者加入聊天室,Chat 應用程式可能會收到批次事件 (google.workspace.chat.membership.v1.batchCreated
)。事件酬載會包含使用者將成員加入聊天室時所建立的所有新 Membership
資源清單。
您會收到訂閱的任何事件類型的大量事件,因此在建立訂閱時,您不需要指定大量事件。舉例來說,如果您訂閱新的回應 (google.workspace.chat.reaction.v1.created
),Chat 應用程式會自動設定為接收批次回應事件 (google.workspace.chat.reaction.v1.batchCreated
)。
下表列出訂閱項目的可能批次事件:
批次事件類型
格式
張貼多則訊息。
google.workspace.chat.message.v1.batchCreated
更新多則訊息。
google.workspace.chat.message.v1.batchUpdated
刪除多則訊息。
google.workspace.chat.message.v1.batchDeleted
建立多個回應。
google.workspace.chat.reaction.v1.batchCreated
系統會刪除多個回應。
google.workspace.chat.reaction.v1.batchDeleted
多位成員加入已訂閱的聊天室,或是已訂閱的使用者加入多個聊天室。
google.workspace.chat.membership.v1.batchCreated
在訂閱空間中或針對訂閱使用者,更新多個會籍。
google.workspace.chat.membership.v1.batchUpdated
多位成員從訂閱的聊天室中移除,或是訂閱者從多個聊天室中移除。
google.workspace.chat.membership.v1.batchDeleted
聊天室有多項更新。
google.workspace.chat.space.v1.batchUpdated
事件資料
本節說明 Chat 中事件的事件資料和酬載範例。
當 Google Workspace 訂閱方案收到 Chat 的事件時,data
欄位會包含事件的酬載。這個酬載包含已變更的 Google Workspace 資源相關資訊。舉例來說,如果您已訂閱聊天室中的會員事件,這些事件的酬載就會包含變更的 spaces.membership
資源相關資訊。
事件酬載中的資源資料
建立訂閱項目時,您可以指定要讓酬載包含資源詳細資料,還是只包含資源名稱。舉例來說,如果您想接收 Chat 聊天室成員的事件,可以指定在事件酬載中接收會員資源的哪些欄位。
下表提供 Chat 聊天室 spaces/AAAABBBBBB
訂閱的 JSON 酬載範例。對於訂閱項目收到的每個事件,酬載都會顯示在事件的 data
欄位中:
範例
事件類型
JSON 酬載
使用者在聊天室中發布「Hello world」的訊息。
google.workspace.chat.message.v1.created
包含資源資料:
{
"message":
{
"name": "spaces/SPACE_ID
/messages/MESSAGE_ID
",
"sender":
{
"name": "users/USER_ID
",
"type": "HUMAN"
},
"createTime": "2023-09-07T21:37:36.260127Z",
"text": "Hello world",
"thread":
{
"name": "spaces/SPACE_ID
/threads/THREAD_ID
"
},
"space":
{
"name": "spaces/SPACE_ID
"
},
"argumentText": "Hello world"
}
}
排除資源資料:
{
"message":
{
"name": "spaces/SPACE_ID
/messages/MESSAGE_ID
"
}
}
使用者成為聊天室管理員。
google.workspace.chat.membership.v1.updated
包含資源資料:
{
"membership":
{
"name": "spaces/SPACE_ID
/members/MEMBER_ID
",
"state": "JOINED",
"member":
{
"name": "users/USER_ID
",
"type": "HUMAN"
},
"createTime": "1970-01-01T00:00:00Z",
"role": "ROLE_MANAGER"
}
}
排除資源資料:
{
"membership":
{
"name": "spaces/SPACE_ID
/members/MEMBER_ID
"
}
}
使用者將聊天室說明更新為「Cymbal Labs 銷售團隊」。
google.workspace.chat.space.v1.updated
包含資源資料:
{
"space":
{
"name": "spaces/SPACE_ID
",
"displayName": "Cymbal Sales",
"spaceThreadingState": "THREADED_MESSAGES",
"spaceType": "SPACE",
"spaceDetails":
{
"description": "Sales team for Cymbal Labs."
},
"spaceHistoryState": "HISTORY_ON"
}
}
排除資源資料:
{
"space":
{
"name": "spaces/SPACE_ID
"
}
}
兩位 Chat 使用者同時加入聊天室。
google.workspace.chat.membership.v1.batchCreated
包含資源資料:
{
"memberships": [
{
"membership": {
"name": "spaces/SPACE_ID
/members/MEMBER_ID
",
"state": "JOINED",
"member":
{
"name": "users/USER_ID
",
"type": "HUMAN"
},
"createTime": "1970-01-01T00:00:00Z",
"role": "ROLE_MEMBER"
}
},
{
"membership": {
"name": "spaces/SPACE_ID
/members/MEMBER_ID
",
"state": "JOINED",
"member":
{
"name": "users/USER_ID
",
"type": "HUMAN"
},
"createTime": "1970-01-01T00:00:00Z",
"role": "ROLE_MEMBER"
}
}
]
}
排除資源資料:
{
"memberships": [
{
"membership": {
"name": "spaces/SPACE_ID
/members/MEMBER_ID
"
}
},
{
"membership": {
"name": "spaces/SPACE_ID
/members/MEMBER_ID
"
}
}
]
}
使用者使用 😊 表情符號回應訊息。
google.workspace.chat.reaction.v1.created
包含資源資料:
{
"reaction":
{
"name": "spaces/SPACE_ID
/messages/MESSAGE_ID
/reactions/REACTION_ID
",
"user":
{
"name": "users/USER_ID
",
"type": "HUMAN"
},
"emoji":
{
"unicode": "😊"
}
}
}
排除資源資料:
{
"reaction":
{
"name": "spaces/SPACE_ID
/messages/MESSAGE_ID
/reactions/REACTION_ID
"
}
}
使用者會使用 😊 和 😸 表情符號回應訊息。
google.workspace.chat.reaction.v1.batchCreated
包含資源資料:
{
"reactions": [
{
"reaction": {
"name": "spaces/SPACE_ID
/messages/MESSAGE_ID
/reactions/REACTION_ID
",
"user":
{
"name": "users/USER_ID
",
"type": "HUMAN"
},
"emoji":
{
"unicode": "😊"
}
}
},
{
"reaction": {
"name": "spaces/SPACE_ID
/messages/MESSAGE_ID
/reactions/REACTION_ID
",
"user":
{
"name": "users/USER_ID
",
"type": "HUMAN"
},
"emoji":
{
"unicode": "😸"
}
}
}
]
}
排除資源資料:
{
"reactions": [
{
"reaction": {
"name": "spaces/SPACE_ID
/messages/MESSAGE_ID
/reactions/REACTION_ID
"
},
"reaction": {
"name": "spaces/SPACE_ID
/messages/MESSAGE_ID
/reactions/REACTION_ID
",
}
}
]
}
限制
針對使用者訂閱,直接訊息或未命名的群組通訊 (google.workspace.chat.membership.v1.created
) 中新成員的事件,只會在發布第一則訊息後觸發。
如要接收會員事件,使用者必須是聊天室的直接成員。如果使用者是透過 Google 群組間接加入聊天室、更新或移除,訂閱項目就不會收到這些會員事件。如要瞭解 Google 群組會員資格運作方式,請參閱「將 Google 群組新增至聊天室 」。
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-24 (世界標準時間)。
想進一步說明嗎?
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-06-24 (世界標準時間)。"],[[["Google Chat apps can subscribe to events like new messages, reactions, membership changes, and space updates using the Google Workspace Events API."],["Subscriptions can target specific spaces, all spaces for a user, or a specific user, enabling customized event delivery."],["Event types are specified when creating subscriptions, with options for receiving detailed resource data or just resource names."],["Batch events are automatically included, grouping multiple similar events for efficiency."],["Certain limitations apply, such as requiring direct space membership for membership events and initial message posting for direct message/unnamed group chat membership events."]]],["Google Chat apps can use the Google Workspace Events API to subscribe to events or query them via the Chat API. Subscribable events include new, updated, or deleted messages, reactions, and members in a space, as well as changes to the space itself. Target resources for subscriptions can be a specific space, all spaces for a user, or a user. Subscriptions can include resource data, and they automatically support batch events. Event types are available for space subscriptions and user subscriptions with some specific limitations.\n"]]