This guide explains how to use the
get()
method on the ThreadReadState
resource of the Google Chat API to get details
about a user's read state within a message thread. To get the read state of a
message in a space, see
Get details about a user's space read state.
The
ThreadReadState
resource
is a singleton resource that represents details about a
specified user's last read message in a Google Chat message thread.
Prerequisites
Node.js
- A Business or Enterprise Google Workspace account with access to Google Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Node.js Cloud Client Library.
-
Create OAuth client ID credentials for a desktop application. To run the sample in this
guide, save the credentials as a JSON file named
client_secrets.json
to your local directory.
- Choose an authorization scope that supports user authentication.
Get the calling user's thread read state
To get details about a user's read state within a message thread, include the following in your request:
- Specify the
chat.users.readstate
orchat.users.readstate.readonly
authorization scope. - Call the
GetThreadReadState()
method, passing thename
of the thread read state to get which includes a user ID or alias and a space ID. Getting thread read state only supports getting the read state of the calling user, which can be specified by setting one of the following:- The
me
alias. For example,users/me/spaces/SPACE/threads/THREAD/threadReadState
. - The calling user's Workspace email address. For example,
users/[email protected]/spaces/SPACE/threads/THREAD/threadReadState
. - The calling user's user ID. For example,
users/USER/spaces/SPACE/threads/THREAD/threadReadState
.
- The
The following example gets the calling user's thread read state:
Node.js
To run this sample, replace the following:
SPACE_NAME
: the ID from the space'sname
. You can obtain the ID by calling theListSpaces()
method or from the space's URL.THREAD_NAME
: the ID from the thread'sname
. You can obtain the ID from the response body returned after creating a message asynchronously with the Chat API, or with the custom name assigned to the message at creation.
The Google Chat API gets the specified thread read state and returns
an instance of
ThreadReadState
.