Get details about a user's thread read state

  • This guide explains how to use the get() method to retrieve a user's read state within a Google Chat message thread using the Google Chat API.

  • The ThreadReadState resource provides details about a user's last read message in a thread.

  • To get the thread read state, you need a Google Workspace account, a configured Google Cloud project with the Google Chat API enabled, and the Node.js Cloud Client Library installed.

  • You must use the chat.users.readstate or chat.users.readstate.readonly authorization scope and call the GetThreadReadState() method, specifying the thread read state's name.

  • The API returns a ThreadReadState instance containing the user's read state information.

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

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 or chat.users.readstate.readonly authorization scope.
  • Call the GetThreadReadState() method, passing the name 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/user@example.com/spaces/SPACE/threads/THREAD/threadReadState.
    • The calling user's user ID. For example, users/USER/spaces/SPACE/threads/THREAD/threadReadState.

The following example gets the calling user's thread read state:

Node.js

chat/client-libraries/cloud/get-thread-read-state-user-cred.js
import{createClientWithUserCredentials}from'./authentication-utils.js';
constUSER_AUTH_OAUTH_SCOPES=[
'https://www.googleapis.com/auth/chat.users.readstate.readonly',
];
// This sample shows how to get the thread read state for a space and calling
// user
asyncfunctionmain(){
// Create a client
constchatClient=awaitcreateClientWithUserCredentials(
USER_AUTH_OAUTH_SCOPES,
);
// Initialize request argument(s)
constrequest={
// Replace SPACE_NAME and THREAD_NAME here
name:'users/me/spaces/SPACE_NAME/threads/THREAD_NAME/threadReadState',
};
// Make the request
constresponse=awaitchatClient.getThreadReadState(request);
// Handle the response
console.log(response);
}
awaitmain();

To run this sample, replace the following:

  • SPACE_NAME: the ID from the space's name. You can obtain the ID by calling the ListSpaces() method or from the space's URL.
  • THREAD_NAME: the ID from the thread's name. 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.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月13日 UTC.