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

このガイドでは、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);
}

await main();

このサンプルを実行するには、SPACE_NAME をスペースの name から取得した ID に置き換えます。ID は、ListSpaces() メソッドを呼び出すか、スペースの URL から取得できます。

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