Get details about a user's thread read state

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

  • TheThreadReadState 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 thechat.users.readstate orchat.users.readstate.readonly authorization scope and call theGetThreadReadState() method, specifying the thread read state's name.

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

This guide explains how to use theget()method on theThreadReadState resource of the Google Chat API to get detailsabout a user's read state within a message thread. To get the read state of amessage in a space, seeGet details about a user's space read state.

TheThreadReadState resourceis a singleton resource that represents details about aspecified user's last read message in a Google Chat message thread.

Prerequisites

Node.js

The code samples in this page use the gRPC API interface with the Google Cloud clientlibraries. Alternatively, you can use the REST API interface. For more information about the gRPCand REST interfaces, seeGoogle Chat API overview.

Get the calling user's thread read state

To get details about a user's read state within a message thread, include thefollowing in your request:

  • Specify thechat.users.readstate orchat.users.readstate.readonlyauthorization scope.
  • Call theGetThreadReadState()method, passing thename of the thread read state to get which includes auser ID or alias and a space ID. Getting thread read state only supportsgetting the read state of the calling user, which can be specified bysetting one of the following:
    • Theme 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// userasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES,);// Initialize request argument(s)constrequest={// Replace SPACE_NAME and THREAD_NAME herename:'users/me/spaces/SPACE_NAME/threads/THREAD_NAME/threadReadState',};// Make the requestconstresponse=awaitchatClient.getThreadReadState(request);// Handle the responseconsole.log(response);}awaitmain();

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 amessage asynchronously with the Chat API, or with thecustom nameassigned to the message at creation.

The Google Chat API gets the specified thread read state and returnsan instance ofThreadReadState.

Related topics

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

Last updated 2025-12-11 UTC.