ユーザーのスペースの通知設定を更新する

このガイドでは、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: ミュートのオンとオフを設定します。値は MUTED または UNMUTED です。
    • 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 に置き換えます。ID は、ListSpaces() メソッドを呼び出すか、スペースの URL から取得できます。

Google Chat API は、指定されたスペースの通知設定を更新し、SpaceNotificationSetting のインスタンスを返します。