使用 Google Chat 进行开发
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面简要介绍了 Google Chat API 和 Google Chat 应用。
Google Chat API 概览
Chat API 由 gRPC 服务或 REST 资源和方法组成,可授予对 Chat 的访问权限,包括聊天室、聊天室成员、消息、消息回应、消息附件、聊天室事件和用户读取状态。
概念
以下部分定义了 Chat API 的服务、资源和方法:
- 聊天室
聊天室是用户和应用可以对话和分享文件的场所。聊天室有多种类型。私信 (DM) 是两位用户之间或用户与 Chat 应用之间的一对一对话。群聊是三位或更多用户与 Chat 应用之间的对话。命名聊天室是持久存在的聊天室,用户可以在其中发送消息、分享文件和协作。
资源参考文档:
如需查看使用示例,请参阅:
- 成员
成员是指已加入聊天室或受邀加入聊天室的用户和 Chat 应用。
资源参考文档:
如需查看使用示例,请参阅:
- 信息
消息包括在聊天室中发布的文本和卡片通信内容。消息可以附加文件。
用户可以通过在消息中附加表情符号来回应消息。
资源参考文档:
如需查看使用示例,请参阅:
- 回应
回应是指用户用来回应消息的表情符号,例如 👍、🚲 和 🌞。
资源参考文档:
如需查看使用示例,请参阅:
- 自定义表情符号
自定义表情符号是指在 Google Chat 中创建并与组织内用户分享的自定义表情符号。自定义表情符号可以包含在消息内容中,也可以用于回应消息。
资源参考文档:
如需查看使用示例,请参阅:
- 媒体和附件
媒体表示上传到 Google Chat 的文件,例如图片、视频和文档。
媒体资源参考(在 RPC 中不可用):
附件是指附加到消息的媒体(文件)实例。
资源参考文档:
如需查看使用示例,请参阅:
- YouTube 空间活动
聊天室事件表示聊天室或其子资源(包括成员、消息和回应)发生了更改。
资源参考文档:
如需查看使用示例,请参阅:
- 用户读取状态
用户读取状态是单例资源,用于表示指定用户在 Google Chat 聊天室或消息串中最后读取的消息的详细信息。
空间读取状态资源参考:
线程读取状态资源参考:
如需查看使用示例,请参阅:
- 用户聊天室通知设置
用户聊天室通知设置是单例资源,表示 Google Chat 聊天室中指定用户的通知设置。
资源参考文档:
身份验证
调用 Chat API 需要进行身份验证。每种 Chat API 方法都需要用户身份验证(代表用户执行操作或访问数据)或应用身份验证(以 Chat 应用的身份执行操作或访问数据)。某些方法同时支持用户身份验证和应用身份验证。
如需详细了解 Chat 中的身份验证,请参阅身份验证概览。
客户端库
对于大多数开发者来说,调用 Google Chat API 的推荐方式是使用我们官方支持的Cloud 客户端库(适用于您偏好的语言,例如 Python、Java 或 Node.js)。
如果您使用 Google Apps 脚本进行编码,请使用高级 Chat 服务,而不是安装客户端库。
构建 Chat 应用
借助 Chat API,您可以构建 Google Chat 应用,将您的服务和资源直接引入 Google Chat。您可以构建聊天应用来执行以下任一操作:
- 根据用户输入的结构化或自由文本查询检索信息。
- 使用用户提供的信息生成突发事件报告或其他制品。
- 增强团队协作,例如提供“团队记忆”或安排资源。
您可以使用多种不同的架构样式来设计 Chat 应用,包括:
- 互动式应用:响应用户互动(例如 @提及或斜杠命令),并通过卡片和对话框呈现信息或引导用户完成工作流程。
- 命令行应用或 Webhook:从其他系统向聊天室发送主动消息,例如闹钟或通知。用户无法直接与此类应用互动。
- 事件驱动型应用:订阅并响应 Chat 聊天室中的活动,例如有新成员加入。应用可以响应事件,发送消息或执行其他操作。
如需详细了解如何设计 Chat 应用,请参阅选择 Google Chat 应用架构。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-04。
[null,null,["最后更新时间 (UTC):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) |"]]