取得使用者的聊天室通知設定

本指南說明如何在 Google Chat API 的 SpaceNotificationSetting 資源上使用 get() 方法,取得使用者的聊天室通知設定。

SpaceNotificationSetting 資源是單例資源,代表指定使用者的空間通知設定的詳細資料。

必要條件

Node.js

取得來電使用者的空間通知設定

如要取得使用者的聊天室通知設定詳細資料,請在要求中加入以下內容:

  • 指定 chat.users.spacesettings 授權範圍。
  • 呼叫 GetSpaceNotificationSetting() 方法,傳遞聊天室通知設定的 name,以取得包含使用者 ID 或別名和聊天室 ID 的內容。您只能取得來電使用者的通知設定。如要指定設定,請使用下列其中一種方法:
    • me 別名。例如 users/me/spaces/SPACE_ID/spaceNotificationSetting
    • 撥打電話的使用者 Google Workspace 電子郵件地址。例如 users/user@example.com/spaces/SPACE_ID/spaceNotificationSetting
    • 呼叫使用者的使用者 ID。例如 users/USER/spaces/SPACE/spaceNotificationSetting

以下範例會取得呼叫使用者的聊天室通知設定:

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

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

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

  // Initialize request argument(s), replace the SPACE_NAME with an actual space name.
  const request = {
    name : 'users/me/spaces/SPACE_NAME/spaceNotificationSetting'
  };

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

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

main().catch(console.error);

如要執行這個範例,請將 SPACE_ID 替換為空間 name 中的 ID。您可以呼叫 ListSpaces() 方法,或從空間的網址取得 ID。

Google Chat API 會取得指定的聊天室通知設定,並傳回 SpaceNotificationSetting 的例項。