取得使用者和 #39 執行緒讀取狀態的詳細資料

本指南說明如何使用 Google Chat API ThreadReadState 資源的 get() 方法,取得訊息串中使用者讀取狀態的詳細資料。如要取得聊天室中訊息的讀取狀態,請參閱「取得使用者的聊天室讀取狀態詳細資料」。

ThreadReadState資源是單例資源,代表 Google Chat 訊息串中指定使用者最後讀取的訊息詳細資料。

必要條件

Node.js

取得通話使用者的執行緒讀取狀態

如要取得郵件串中使用者讀取狀態的詳細資料,請在要求中加入下列項目:

  • 指定 chat.users.readstatechat.users.readstate.readonly 授權範圍。
  • 呼叫 GetThreadReadState() 方法,傳遞執行緒讀取狀態的 name,其中包含使用者 ID 或別名和空間 ID。取得執行緒讀取狀態時,系統只支援取得呼叫使用者的讀取狀態,您可以透過設定下列其中一項來指定:
    • me 別名。例如 users/me/spaces/SPACE/threads/THREAD/threadReadState
    • 通話使用者的 Workspace 電子郵件地址。例如 users/user@example.com/spaces/SPACE/threads/THREAD/threadReadState
    • 發出呼叫的使用者 ID。例如 users/USER/spaces/SPACE/threads/THREAD/threadReadState

以下範例會取得呼叫使用者的執行緒讀取狀態:

Node.js

chat/client-libraries/cloud/get-thread-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 thread read state for a space and 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 and THREAD_NAME here
    name: 'users/me/spaces/SPACE_NAME/threads/THREAD_NAME/threadReadState',
  };

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

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

main().catch(console.error);

如要執行這個範例,請替換下列項目:

  • SPACE_NAME:來自聊天室 name 的 ID。您可以呼叫 ListSpaces() 方法或從空間的網址取得 ID。
  • THREAD_NAME:執行緒的 ID,來自執行緒的 name。 您可以透過使用 Chat API 非同步建立訊息後傳回的回應主體,或透過建立訊息時指派給訊息的自訂名稱,取得 ID。

Google Chat API 會取得指定討論串的已讀狀態,並傳回 ThreadReadState 的執行個體。