使用 Google Chat 開發
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁面提供 Google Chat API 和 Google Chat 應用程式的總覽。
Google Chat API 總覽
Chat API 包含 gRPC 服務或 REST 資源和方法,可授予 Chat 存取權,包括聊天室、聊天室成員、訊息、訊息回應、訊息附件、聊天室事件和使用者讀取狀態。
概念
以下各節定義了 Chat API 的服務、資源和方法:
- Spaces
聊天室是使用者和應用程式可以對話及分享檔案的地方。聊天室分為幾種類型,即時訊息 (DM) 是指兩位使用者之間,或使用者與 Chat 應用程式之間的 1 對 1 對話。群組對話是指三位以上使用者與 Chat 應用程式之間的對話。具名聊天室是持續存在的空間,使用者可以在其中傳送訊息、共用檔案及協作。
資源參照:
如需使用範例,請參閱:
- 成員
成員是指已加入或受邀加入聊天室的使用者和 Chat 應用程式。
資源參照:
如需使用範例,請參閱:
- 訊息
訊息包括在聊天室中發布的文字和資訊卡通訊內容。訊息可以附加檔案。
使用者可以在訊息中附加表情符號來回應。
資源參照:
如需使用範例,請參閱:
- 反應
回應是指使用者用來回應訊息的表情符號,例如 👍、🚲 和 🌞。
資源參照:
如需使用範例,請參閱:
- 自訂表情符號
自訂表情符號:在 Google Chat 中建立並與機構共用的自訂表情符號。自訂表情符號可加入訊息內容,或用來回應訊息。
資源參照:
如需使用範例,請參閱:
- 媒體和附件
媒體是指上傳到 Google Chat 的檔案,例如圖片、影片和文件。
媒體資源參照 (不適用於 RPC):
附件是指附加至訊息的媒體 (檔案) 執行個體。
資源參照:
如需使用範例,請參閱:
- Space 活動
聊天室事件代表聊天室或其子項資源的變更,包括成員、訊息和回應。
資源參照:
如需使用範例,請參閱:
- 使用者讀取狀態
使用者讀取狀態是單例資源,代表 Google Chat 空間或訊息串中,特定使用者上次讀取訊息的詳細資料。
空間讀取狀態資源參照:
執行緒讀取狀態資源參考資料:
如需使用範例,請參閱:
- 使用者空間通知設定
使用者聊天室通知設定是單例資源,代表 Google Chat 聊天室中特定使用者的通知設定。
資源參照:
驗證
呼叫 Chat API 時需要驗證。每個 Chat API 方法都需要使用者驗證 (代表使用者執行動作或存取資料),或應用程式驗證 (以 Chat 應用程式身分執行動作或存取資料)。部分方法同時支援使用者驗證和應用程式驗證。
如要進一步瞭解 Chat 的驗證機制,請參閱驗證總覽。
用戶端程式庫
對大多數開發人員而言,呼叫 Google Chat API 的建議方式是使用我們正式支援的Cloud 用戶端程式庫,並選擇您偏好的語言,例如 Python、Java 或 Node.js。
如果您使用 Google Apps Script 進行編碼,請改用進階 Chat 服務,不必安裝用戶端程式庫。
建構 Chat 擴充應用程式
透過 Chat API,您可以建構 Google Chat 應用程式,將服務和資源直接帶進 Google Chat。您可以建構 Chat 應用程式,執行下列任一操作:
- 根據使用者輸入的結構化或任意文字查詢,擷取資訊。
- 使用使用者提供的資訊,產生事件報告或其他構件。
- 提升團隊協作效率,例如提供「團隊記憶」或安排資源。
您可以透過幾種不同的架構樣式設計 Chat 應用程式,包括:
- 互動式應用程式:回應使用者互動,例如 @提及或斜線指令,並透過資訊卡和對話方塊呈現資訊或引導使用者完成工作流程。
- 指令列應用程式或 Webhook:從其他系統將主動訊息 (例如鬧鐘或通知) 傳送至聊天室。使用者無法直接與這類應用程式互動。
- 事件驅動型應用程式:訂閱及回應 Chat 聊天室中的活動,例如有新成員加入。應用程式可以傳送訊息或執行其他動作,以回應事件。
如要進一步瞭解如何設計 Chat 應用程式,請參閱「選擇 Google Chat 應用程式架構」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-04 (世界標準時間)。
[null,null,["上次更新時間:2025-08-04 (世界標準時間)。"],[[["\u003cp\u003eGoogle Chat apps integrate services directly into chats, enabling users to access information and take action without leaving the conversation.\u003c/p\u003e\n"],["\u003cp\u003eThese apps support various functionalities, including workflow management, data collection, and interactive elements like dialogs and slash commands.\u003c/p\u003e\n"],["\u003cp\u003eChoose from interactive, non-interactive, or event-driven architectures to build apps that cater to your specific needs and use cases.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Chat apps can be built using various platforms like AppSheet, Google Apps Script, and Dialogflow.\u003c/p\u003e\n"],["\u003cp\u003eAccess to user data beyond basic identity requires authentication and user consent, ensuring privacy and security.\u003c/p\u003e\n"]]],["Google Chat apps integrate services directly into conversations, allowing users to access information and perform actions without leaving the chat. These apps can send text or card messages within spaces or direct messages. They can be interactive, responding to mentions and commands, or non-interactive, sending messages without user interaction. Apps can retrieve information, file tickets, and coordinate team efforts. Developers can build these apps using diverse platforms, manage deployments, and publish them on the Google Workspace Marketplace.\n"],null,["# Develop with Google Chat\n\nThis page provides an overview of the Google Chat API and Google Chat apps.\n\nGoogle Chat API overview\n------------------------\n\nThe Chat API consists of\n[gRPC services or REST resources and methods](https://cloud.google.com/apis/docs/client-libraries-explained)\nthat grant access to Chat, including spaces, space members,\nmessages, message reactions, message attachments, space events, and user read\nstates.\n\n### Concepts\n\nThe following section defines the services, resources, and methods for the\nChat API:\n\n*Spaces*\n\n: *Spaces* are places where people and apps can converse and share files. There\n are several types of spaces. Direct messages (DMs) are 1:1 conversations\n between two users or a user and a Chat app. Group\n chats are conversations between three or more users and\n Chat apps. Named spaces are persistent places where people send\n messages, share files, and collaborate.\n\n: Resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Space)\n - [REST reference](/workspace/chat/api/reference/rest/v1/spaces)\n\n: For example usage, see:\n\n - [Create a space](/workspace/chat/create-spaces)\n - [Set up a space](/workspace/chat/set-up-spaces)\n - [Get a space](/workspace/chat/get-spaces)\n - [List spaces](/workspace/chat/list-spaces)\n - [Update a space](/workspace/chat/update-spaces)\n - [Delete a space](/workspace/chat/delete-spaces)\n - [Find a direct message (DM)](/workspace/chat/find-direct-message-in-spaces)\n\n*Members*\n\n: *Members* are users and Chat apps that have joined or are\n invited to a space.\n\n: Resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Membership)\n - [REST reference](/workspace/chat/api/reference/rest/v1/spaces.members)\n\n: For example usage, see:\n\n - [Create a membership](/workspace/chat/create-members)\n - [Get a membership](/workspace/chat/get-members)\n - [List memberships](/workspace/chat/list-members)\n - [Update a membership](/workspace/chat/update-members)\n - [Delete a membership](/workspace/chat/delete-members)\n\n*Messages*\n\n: *Messages* include\n [text](/workspace/chat/api/reference/rest/v1/spaces.messages)\n and\n [card](/workspace/chat/api/reference/rest/v1/cards)\n communications posted in spaces. Messages can have files attached to them.\n People can react to messages by appending emoji to them.\n\n: Resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Message)\n - [REST reference](/workspace/chat/api/reference/rest/v1/spaces.messages)\n\n: For example usage, see:\n\n - [Create a message](/workspace/chat/create-messages)\n - [Get a message](/workspace/chat/get-messages)\n - [List messages](/workspace/chat/list-messages)\n - [Update a message](/workspace/chat/update-messages)\n - [Delete a message](/workspace/chat/delete-messages)\n\n*Reactions*\n\n: *Reactions* represent the emoji people use to react to a message, such as\n 👍, 🚲, and 🌞.\n\n: Resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Reaction)\n - [REST reference](/workspace/chat/api/reference/rest/v1/spaces.messages.reactions)\n\n: For example usage, see:\n\n - [Create a reaction](/workspace/chat/create-reactions)\n - [List reactions](/workspace/chat/list-reactions)\n - [Delete a reaction](/workspace/chat/delete-reactions)\n\n*Custom emoji*\n\n: *Custom emoji* represent custom emoji created and shared within the\n organization in Google Chat. Custom emoji can be included in the content of\n a message or used to react to a message.\n\n: Resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.CustomEmoji)\n - [REST reference](/workspace/chat/api/reference/rest/v1/customEmojis)\n\n: For example usage, see:\n\n - [Create a custom emoji](/workspace/chat/create-custom-emoji)\n - [Delete a custom emoji](/workspace/chat/delete-custom-emoji)\n - [Get details about a custom emoji](/workspace/chat/get-custom-emoji)\n - [List custom emojis in an organization](/workspace/chat/list-custom-emojis)\n\n*Media and attachments*\n\n: *Media* represents a file uploaded to Google Chat, like images, videos, and\n documents.\n\n: Media resource reference (Unavailable in RPC):\n\n - [REST reference](/workspace/chat/api/reference/rest/v1/media)\n\n: *Attachments* are instances of media (files) attached to messages.\n\n: Resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Attachment)\n - [REST reference](/workspace/chat/api/reference/rest/v1/spaces.messages.attachments)\n\n: For example usage, see:\n\n - [Upload media as an attachment](/workspace/chat/upload-media-attachments)\n - [Download media as an attachment](/workspace/chat/download-media-attachments)\n - [Get an attachment](/workspace/chat/get-media-attachments)\n\n*Space events*\n\n: *Space events* represent changes to a space or its\n child resources, including its members, messages, and reactions.\n\n: Resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceEvent)\n - [REST reference](/workspace/chat/api/reference/rest/v1/spaces.spaceEvents)\n\n: For example usage, see:\n\n - [Get space read state](/workspace/chat/get-space-read-state)\n - [Update space read state](/workspace/chat/update-space-read-state)\n - [Get thread read state](/workspace/chat/get-thread-read-state)\n\n*User read states*\n\n: *User read states* are singleton resources that represent details about a\n specified user's last read message in a Google Chat space or a message\n thread.\n\n: Space read state resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceReadState)\n - [REST reference](/workspace/chat/api/reference/rest/v1/users.spaces)\n\n: Thread read state resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ThreadReadState)\n - [REST reference](/workspace/chat/api/reference/rest/v1/users.spaces.threads)\n\n: For example usage, see:\n\n - [Get space read state](/workspace/chat/get-space-read-state)\n - [Update space read state](/workspace/chat/update-space-read-state)\n - [Get thread read state](/workspace/chat/get-thread-read-state)\n\n*User space notification settings*\n\n: *User space notification settings* are singleton resources that represent a\n specified user notification settings in a Google Chat space.\n\n: Resource reference:\n\n - [RPC reference](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceNotificationSetting)\n - [REST reference](/workspace/chat/api/reference/rest/v1/users.spaces.spaceNotificationSetting)\n\n### Authentication\n\nCalling the Chat API requires authentication. Each\nChat API method requires either\n[user authentication](/workspace/chat/authenticate-authorize-chat-user)\n(to perform actions or access\ndata on behalf of a user) or\n[app authentication](/workspace/chat/authenticate-authorize-chat-app)\n(to perform actions or access data as a Chat app). Some\nmethods support both user authentication and app authentication.\n\nTo learn more about authentication in Chat, see\n[Authentication overview](/workspace/chat/authenticate-authorize).\n\n### Client libraries\n\nThe recommended way for most developers to call the Google Chat API\nis with our officially supported\n[Cloud Client Libraries](/workspace/chat/libraries)\nfor your preferred language, like Python, Java, or Node.js.\n\nIf you're coding with Google Apps Script, use the\n[Advanced Chat service](/apps-script/advanced/chat)\ninstead of installing a client library.\n\nBuild Chat apps\n---------------\n\nThe Chat API lets you build Google Chat apps that bring your\nservices and resources right into Google Chat. You can build\nChat apps to do any of the following:\n\n- Retrieve information based on structured or free text queries entered by the user.\n- Generate incident reports or other artifacts, using information provided by the user.\n- Enhance team collaboration, such as providing \"team memory\" or scheduling resources.\n\nYou can design your Chat app using several different\narchitecture styles, including the following:\n\n- **Interactive apps**: Respond to user interaction, such as @mentions or slash commands, and present information or guide users through a workflow with cards and dialogs.\n- **Command-line apps or webhooks**: Send proactive messages, such as alarms or notifications, from another system into a space. Users can't directly interact with this type of app.\n- **Event-driven apps**: Subscribe to and react to activity in a Chat space, such as a new member joining. In response to an event, the app can send a message or perform another action.\n\nFor details about designing your Chat app, see\n[Choose a Google Chat app architecture](/workspace/chat/structure).\n\nRelated topics\n--------------\n\n- [Explore Google Chat app samples](/workspace/chat/samples).\n- [Build interactive Google Chat apps](/workspace/chat/interact-users-overview).\n- [Choose a Google Chat app architecture](/workspace/chat/structure).\n\n|---|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | Want to see the Google Chat API in action? The Google Workspace Developers channel offers videos about tips, tricks, and the latest features. [Subscribe now](https://www.youtube.com/channel/UCUcg6az6etU_gRtZVAhBXaw) |"]]