Get details about a user's space read state

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

The SpaceReadState resource is a singleton resource that represents details about a specified user's last read message in a Google Chat space.

Prerequisites

Node.js

Get the calling user's space read state

To get details about a user's read state within a space, include the following in your request:

  • Specify the chat.users.readstate or chat.users.readstate.readonly authorization scope.
  • Call the GetSpaceReadState() method, passing the name of the space read state to get which includes a user ID or alias and a space ID. Getting space 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/spaceReadState.
    • The calling user's Workspace email address. For example, users/user@example.com/spaces/SPACE/spaceReadState.
    • The calling user's user ID. For example, users/USER/spaces/SPACE/spaceReadState.

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

Node.js

chat/client-libraries/cloud/get-space-read-state-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';

const USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.users.readstate.readonly'];

// This sample shows how to get the space read state for the calling user
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);

  // Initialize request argument(s)
  const request = {
    // Replace SPACE_NAME here
    name: 'users/me/spaces/SPACE_NAME/spaceReadState'
  };

  // Make the request
  const response = await chatClient.getSpaceReadState(request);

  // Handle the response
  console.log(response);
}

main().catch(console.error);

To run this sample, replace SPACE_NAME with the ID from the space's name. You can obtain the ID by calling the ListSpaces() method or from the space's URL.

The Google Chat API gets the specified space read state and returns an instance of SpaceReadState.