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

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

main().catch(console.error);

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

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