更新使用者的聊天室通知設定

本指南說明如何使用 Google Chat API SpaceNotificationSetting 資源的 patch() 方法,更新使用者的聊天室通知設定。

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

必要條件

Node.js

更新通話使用者的聊天室通知設定

如要更新使用者的空間通知設定,請在要求中加入下列項目:

  • 指定 chat.users.spacesettings 授權範圍。
  • 呼叫 UpdateSpaceNotificationSetting() 方法,傳遞 UpdateSpaceNotificationSetting 要求,其中包含通知設定的變更。要求包括:
    • spaceNotificationSetting,並具有下列屬性:
      • name 屬性會指定要更新的聊天室通知設定,包括使用者 ID 或別名和聊天室 ID。更新聊天室通知設定時,只能更新通話使用者的通知設定,可透過設定下列其中一項來指定:
        • me 別名。例如 users/me/spaces/SPACE/spaceNotificationSetting
        • 通話使用者的 Workspace 電子郵件地址。例如 users/user@example.com/spaces/SPACE/spaceNotificationSetting
        • 發出呼叫的使用者 ID。例如 users/USER/spaces/SPACE/spaceNotificationSetting
      • notificationSetting:設定通知層級,例如 ALLOFF
      • muteSetting:設定靜音開啟或關閉,值可以是 MUTEDUNMUTED
    • updateMask:設定更新欄位,可包含 notification_settingmute_setting

以下範例會更新通話使用者的聊天室通知設定:

Node.js

chat/client-libraries/cloud/update-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 update 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 = {
    spaceNotificationSetting: {
      name: 'users/me/spaces/SPACE_NAME/spaceNotificationSetting',
      notificationSetting: 'ALL',
      muteSetting: 'UNMUTED',
    },
    updateMask: {paths: ['notification_setting', 'mute_setting']},
  };

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

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

await main();

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

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