识别并指定 Google Chat 用户
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页介绍了 Google Chat 应用可以识别或指定 Chat 用户的方式。
如需执行以下任何操作,Chat 应用都必须指定用户:
Chat 如何识别用户
Google Chat API 会为每个使用 Chat 的用户生成一个 User
资源。以下是两个重要的 User
字段:
name
是资源的资源名称,格式为 users/{user}
,其中 {user}
表示唯一且稳定的标识符。users/app
可用作发起调用的 Chat 应用的别名。
type
是用户类型。此类型用于告知 Chat 用户是 Chat 应用还是个人。对于聊天应用,该值为 BOT
。对于人员,该值为 HUMAN
。
在调用 Google Chat API 时指定用户
如需指定用户,请为 {user}
值使用以下值:
从互动事件中识别用户
每当用户与 Chat 应用互动时,Chat 都会发送包含互动和用户相关信息的互动事件。例如,当用户在消息中提及 Chat 应用时,Chat 应用会收到与该互动相关的信息,包括消息内容以及发件人。Chat 应用在检索 Chat 资源的相关信息时会引用用户。
如需识别与 Chat 应用互动的用户,请获取 User
资源上的 name
属性的值,您可以从 Event.user.name
获取该值。
以下 JSON 示例展示了与 Chat 应用互动时用户身份的预期格式:
{
...,
"user": {
"name": "users/12345678901234567890",
"displayName": "Sasha",
"avatarUrl": "https://lh3.googleusercontent.com/.../photo.jpg",
"email": "sasha@example.com"
}
}
消息是一种特定类型的互动。如需识别向 Chat 应用发送消息的用户,请使用以下任一方法获取 User
资源上的 name
属性的值:
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-12-21。
[null,null,["最后更新时间 (UTC):2024-12-21。"],[[["\u003cp\u003eGoogle Chat apps can identify users through a unique \u003ccode\u003eUser\u003c/code\u003e resource with a \u003ccode\u003ename\u003c/code\u003e and \u003ccode\u003etype\u003c/code\u003e field to distinguish between bots and humans.\u003c/p\u003e\n"],["\u003cp\u003eYou can specify a user in API calls using their resource name, Person resource ID, Directory API ID, or email alias depending on their location and account type.\u003c/p\u003e\n"],["\u003cp\u003eChat apps receive user information during interactions through the \u003ccode\u003eUser\u003c/code\u003e resource within the event data, allowing identification and actions based on user details.\u003c/p\u003e\n"],["\u003cp\u003eUser identification enables features like mentioning users in messages, adding them to spaces, managing memberships, sending private messages, and subscribing to events.\u003c/p\u003e\n"],["\u003cp\u003eResources such as the \u003ccode\u003eUser\u003c/code\u003e and \u003ccode\u003ePerson\u003c/code\u003e objects, along with API guides, are available for further understanding and implementing user management in Chat apps.\u003c/p\u003e\n"]]],["Google Chat apps specify users to perform actions like @-mentioning, adding users to spaces, finding direct messages, retrieving membership details, sending private messages, and subscribing for membership change events. Users are identified via a `User` resource, with a unique `name` (e.g., `users/123456789`) and `type` (`BOT` or `HUMAN`). External users are specified using email aliases. Interactions with the Chat app include the user's `name` in the `Event.user.name` property.\n"],null,[]]