Page Summary
-
Google Chat apps can identify users through a unique
Userresource with anameandtypefield to distinguish between bots and humans. -
You 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.
-
Chat apps receive user information during interactions through the
Userresource within the event data, allowing identification and actions based on user details. -
User identification enables features like mentioning users in messages, adding them to spaces, managing memberships, sending private messages, and subscribing to events.
-
Resources such as the
UserandPersonobjects, along with API guides, are available for further understanding and implementing user management in Chat apps.
This page explains how Google Chat apps and developers can identify and specify Chat users.
To do any of the following, a Chat app or developer must specify a user:
- Create a message that @ mentions a user.
- Invite or add a user to an existing space, or add a user to a new space.
- Find direct messages between the Chat app and a specified user, or between two users.
- Get a user's membership details in a space.
- Send a private message to a user.
- Subscribe to a user using the Google Workspace Events API to get events about their membership changes.
How Chat identifies users
The Google Chat API generates a
User resource
for each person and app that uses Chat. A User resource
contains the following fields:
name: The resource name, formatted asusers/{user}, where{user}represents a unique and stable identifier. You can useusers/appas an alias for the calling Chat app.displayName: Output only. The user's display name.avatarUrl: Output only. The user's avatar image URL.email: Output only. The user's email address.domainId: Unique identifier of the user's Google Workspace domain.type: The type of user. This indicates whether the user is a Chat app (BOT) or a person (HUMAN).isAnonymous: Output only. Whentrue, indicates that the user is deleted or their profile is not visible.
User profile details and visibility rules
When calling the Messages and Memberships APIs using
user authentication,
the Google Chat API populates the User resource with profile details.
The API populates displayName, email, and avatarUrl for both internal
users (in your Google Workspace organization) and external users (in external
organizations or personal Google Accounts).
Examples of where the API populates user profiles include the following locations:
- The
senderof aMessage. - Users within message
annotations, such as user@mentions. - The
memberwithin aMembershipresource.
Privacy and visibility rules
To protect user privacy, the Google Chat API applies specific visibility rules when determining whether to populate a user's profile details:
- Populated profile: The API populates profile details (
displayName,email, andavatarUrlare present, andisAnonymousisfalse) if the user has accepted a space invitation (is a member of the space) or has a prior affinity (such as a direct message interaction history) with the calling user. - Anonymous profile: If a user is mentioned in a space without being a
member and without prior affinity with the calling user, their profile
remains anonymous. For an anonymous user,
isAnonymousistrue, and details likedisplayName,email, andavatarUrlare omitted. However, for API requests made with app authentication, thedisplayNamefield always populates.
The following JSON example shows a User resource with populated profile
details returned in an API response or interaction event:
{
"name": "users/12345678901234567890",
"displayName": "Sasha",
"domainId": "123abc",
"avatarUrl": "https://lh3.googleusercontent.com/.../photo.jpg",
"email": "sasha@example.com",
"type": "HUMAN",
"isAnonymous": false
}
The following JSON example shows an anonymous User resource where the
user profile details are not visible to the caller:
{
"name": "users/10987654321098765432",
"type": "HUMAN",
"isAnonymous": true
}
Specify a user in a call to the Google Chat API
To specify a user, use the following values for the {user} value:
For users in your Google Workspace organization, use one of the following approaches:
- The
nameof theUserresource in the Chat API, such asusers/123456789. - The
{person_id}for the name of aPersonresource in the People API, where theresourceNameispeople/{person_id}—for example,users/123456789in the Chat API represents the same person aspeople/123456789in the People API. - The
idfor aUserresource in the Directory API—for example,users/123456789in the Chat API represents the same person asusers/123456789in the Directory API. - For API requests made with
user authentication,
the user's email address as an alias—for example,
users/EMAIL_USERNAME@WORKSPACE_DOMAIN.com.
- The
For a user in an external Google Workspace organization, or a user who uses a Google Account, use one of the following:
- An email alias—for example,
users/EMAIL_USERNAME@WORKSPACE_DOMAIN.comorusers/EMAIL_USERNAME@gmail.com. - The canonical
nameof theUserresource (such asusers/12345678901234567890) obtained from a prior API call or interaction event.
- An email alias—for example,
Identify a user from an API response or interaction event
You can identify users returned from API calls or incoming events in several ways:
- Messages API: Get the sender's identity from
Message.senderor mentioned users fromMessage.annotations[].userMention.user. - Memberships API: Get the member's identity from
Membership.member. - Interaction events: When a user interacts with a
Chat app, Chat sends an
interaction event with the
user's identity in
Event.user.
Because the Google Chat API populates profiles for both internal and external users when using user authentication, developers don't need to call the Directory API to resolve names or emails for members and message senders.
Related topics
- Authenticate and authorize as a Google Chat user.
- Add a user to a space.
- Manage members in a space.
- @ mention a user in a message.
Userresource REST API reference.