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

本指南說明如何使用 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);
}

await main();

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

Google Chat API 會取得指定的聊天室通知設定,並傳回 SpaceNotificationSetting 的執行個體。