訂閱 Google Chat 活動

本頁面說明 Google Chat 應用程式的 Google Chat 事件 ,使用 Google Workspace Event API 訂閱。在您決定 您需要的事件類型、建立 訂閱即可開始接收 以及 Google Chat 中的活動。

除了訂閱事件外,您也可以透過呼叫 Chat API。呼叫 Chat API 可讓您 定期擷取事件 顯示您可能因為服務中斷而錯過訂閱的事件。學習 瞭解如何接收及回覆 Chat 事件。請參閱 在以下聊天室中使用 Google Chat 中的活動: Chat 說明文件。

支援的 Chat 事件

Google Workspace 訂閱可讓你接收 下列類型的 Chat 異動:

  • 新增、更新或刪除訊息 見證這一點
  • 新增或移除的回應 訊息。
  • 新增、更新或移除成員 見證這一點
  • 聊天室異動 訂閱的聊天室,例如更新的聊天室名稱或說明。

可監控事件的資源

如要接收活動,請指定您要監控的 Chat 資源、 也就是訂閱項目的「目標資源」

Google Workspace 活動 API 支援下列目標資源 即時通訊:

目標資源 格式 限制
空格

//chat.googleapis.com/spaces/SPACE

其中 SPACE Chat API space 資源的資源名稱。 您可以從聊天室網址或使用 spaces.list() 方法,增加圍繞地圖邊緣的邊框間距。

授權訂閱的 Chat 使用者必須 透過 Google Workspace 或 Google 加入聊天室成員 。
使用者的所有聊天室

//chat.googleapis.com/spaces/-

訂閱項目只會收到使用者所屬聊天室的事件 成員透過 Google Workspace 或 Google 帳戶註冊
使用者

//cloudidentity.googleapis.com/users/USER

其中 USER Chat API user 資源的資源名稱。 詳情請參閱 識別與指定 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 應用程式可能也會接收批次事件。批次事件 是一種事件,代表 Shorts 中發生的許多相同類型的事件 範圍。批次事件的酬載包含所有已變更 再複習一下,機構節點 是所有 Google Cloud Platform 資源的根節點

舉例來說,如果使用者同時在聊天室中加入 20 位使用者,您的 Chat 應用程式可能會收到批次事件 (google.workspace.chat.membership.v1.batchCreated)。事件酬載包含 列出使用者建立的所有新 Membership 資源 已將成員加入聊天室。

您訂閱的任何事件類型都會收到批次事件,因此 您不必在建立訂閱項目時指定批次事件。適用對象 假設您訂閱了新的表情符號 (google.workspace.chat.reaction.v1.created),您的 即時通訊應用程式會自動設為接收批次 回應事件 (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

事件資料

本節將說明 。

您的 Google Workspace 訂閱方案收到事件時 Chat、 data 欄位包含事件的酬載。這個酬載包含 已變更的 Google Workspace 資源。舉例來說,如果您已訂閱 在聊天室中成員資格事件時,這些事件的酬載會包含資訊 關於 spaces.membership 變更的資源

事件酬載中的資源資料

建立訂閱項目時,您可以指定是否希望酬載 包含資源的詳細資料或僅包含資源名稱適用對象 舉例來說,在 Chat 中希望收到會員相關活動時 您可以指定要接收哪些成員資源的欄位 事件酬載中

下表提供訂閱項目的 JSON 酬載範例 「spaces/AAAABBBBBB」Chat 聊天室。對於 使用者收到訂閱項目後,酬載就會出現在事件的 data 欄位中:

範例 事件類型 JSON 酬載

使用者在聊天室中張貼了「Hello World」訊息。

google.workspace.chat.message.v1.created

包含資源資料
{
    "message":
    {
        "name": "spaces/AAAABBBBBB/messages/CCCCCCCCC.DDDDDDDDD",
        "sender":
        {
            "name": "users/1234567890987654321",
            "type": "HUMAN"
        },
        "createTime": "2023-09-07T21:37:36.260127Z",
        "text": "Hello world",
        "thread":
        {
            "name": "spaces/AAAABBBBBB/threads/EEEEEEEEEEEE"
        },
        "space":
        {
            "name": "spaces/AAAABBBBBB"
        },
        "argumentText": "Hello world"
    }
}
      
不含資源資料
{
    "message":
    {
        "name": "spaces/AAAABBBBBB/messages/CCCCCCCCC.DDDDDDDDD"
    }
}
      
使用者將成為聊天室管理員。

google.workspace.chat.membership.v1.updated

包含資源資料
{
    "membership":
    {
        "name": "spaces/AAAABBBBBB/members/1234567890987654321",
        "state": "JOINED",
        "member":
        {
            "name": "users/1234567890987654321",
            "type": "HUMAN"
        },
        "createTime": "1970-01-01T00:00:00Z",
        "role": "ROLE_MANAGER"
    }
}
      
不含資源資料
{
    "membership":
    {
        "name": "spaces/AAAABBBBBB/members/1234567890987654321"
    }
}
      
使用者將聊天室說明更新為「Cymbal Labs 銷售團隊」。 google.workspace.chat.space.v1.updated
包含資源資料
{
    "space":
    {
        "name": "spaces/AAAABBBBBB",
        "displayName": "Cymbal Sales",
        "spaceThreadingState": "THREADED_MESSAGES",
        "spaceType": "SPACE",
        "spaceDetails":
        {
            "description": "Sales team for Cymbal Labs."
        },
        "spaceHistoryState": "HISTORY_ON"
    }
}
      
不含資源資料
{
    "space":
    {
        "name": "spaces/AAAABBBBBB"
    }
}
      
聊天室中同時有 2 位 Chat 使用者加入聊天室。 google.workspace.chat.membership.v1.batchCreated
包含資源資料
{
    "memberships": [
        {
          "membership": {
            "name": "spaces/AAAABBBBBB/members/1234567890987654321",
            "state": "JOINED",
            "member":
            {
                "name": "users/1234567890987654321",
                "type": "HUMAN"
            },
            "createTime": "1970-01-01T00:00:00Z",
            "role": "ROLE_MEMBER"
          }
        },
        {
          "membership": {
            "name": "spaces/AAAABBBBBB/members/987654321234567890",
            "state": "JOINED",
            "member":
            {
                "name": "users/987654321234567890",
                "type": "HUMAN"
            },
            "createTime": "1970-01-01T00:00:00Z",
            "role": "ROLE_MEMBER"
          }
        }
    ]
}
      
不含資源資料
{
    "memberships": [
        {
          "membership": {
            "name": "spaces/AAAABBBBBB/members/1234567890987654321"
          }
        },
        {
          "membership": {
            "name": "spaces/AAAABBBBBB/members/98765432123456789019"
          }
        }
    ]
}
      
使用者以 😊? 表情符號回應訊息。 google.workspace.chat.reaction.v1.created
包含資源資料
{
    "reaction":
    {
        "name": "spaces/AAAABBBBBB/messages/123456789.123456789/reactions/1111111111111111.222222222222222",
        "user":
        {
            "name": "users/1234567890987654321",
            "type": "HUMAN"
        },
        "emoji":
        {
            "unicode": "😊"
        }
    }
}
      
省略資源資料
{
    "reaction":
    {
        "name": "spaces/AAAABBBBBB/messages/123456789.123456789/reactions/1111111111111111.222222222222222"
    }
}
      
使用者以 😊? 表情符號和 😸? 表情符號回應訊息。 google.workspace.chat.reaction.v1.batchCreated
包含資源資料
{
    "reactions": [
        {
          "reaction": {
            "name": "spaces/AAAABBBBBB/messages/123456789.123456789/reactions/1111111111111111.222222222222222",
            "user":
            {
                "name": "users/1234567890987654321",
                "type": "HUMAN"
            },
            "emoji":
            {
                "unicode": "😊"
            }
          }
        },
        {
          "reaction": {
            "name": "spaces/AAAABBBBBB/messages/123456789.123456789/reactions/3333333333333333.444444444444444",
            "user":
            {
                "name": "users/98765431234564321",
                "type": "HUMAN"
            },
            "emoji":
            {
                "unicode": "😸"
            }
          }
        }
    ]
}
      
省略資源資料
{
    "reactions": [
      {
        "reaction": {
            "name": "spaces/AAAABBBBBB/messages/123456789.123456789/reactions/1111111111111111.222222222222222"
        },
        "reaction": {
            "name": "spaces/AAAABBBBBB/messages/123456789.123456789/reactions/3333333333333333.444444444444444",
        }
      }
    ]
}
      

限制

  • 如果是訂閱使用者訂閱,則即時訊息或未命名群組通訊中的新成員事件 (google.workspace.chat.membership.v1.created)、 只會在第一則訊息張貼後觸發。
  • 使用者必須是聊天室的直接成員,才能接收成員資格活動。如果已新增使用者 使用者透過 Google 群組間接更新或移除聊天室,但訂閱作業不會 接收這些會員資格事件如要瞭解 Google 網路論壇成員資格的運作方式,請參閱: 將 Google 群組新增至聊天室