This guide explains how to use the
patch()
method on the SpaceNotificationSetting
resource of the Google Chat API to update
a user's space notification settings.
The
SpaceNotificationSetting
resource
is a singleton resource that represents details about a specified user's space
notification settings.
Prerequisites
Node.js
- A Business or Enterprise Google Workspace account with access to Google Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Node.js Cloud Client Library.
-
Create OAuth client ID credentials for a desktop application. To run the sample in this
guide, save the credentials as a JSON file named
client_secrets.json
to your local directory.
- Choose an authorization scope that supports user authentication.
Update the calling user's space notification settings
To update a user's space notification setting, include the following in your request:
- Specify the
chat.users.spacesettings
authorization scope. - Call the
UpdateSpaceNotificationSetting()
method, passingUpdateSpaceNotificationSetting
request to contain the changes to the notification settings. The request includes:spaceNotificationSetting
with the following properties:- The
name
property specifies which space notification settings to update which includes a user ID or alias and a space ID. Updating space notification settings only supports updating the notification settings of the calling user, which can be specified by setting one of the following:- The
me
alias. For example,users/me/spaces/SPACE/spaceNotificationSetting
. - The calling user's Workspace email address. For example,
users/user@example.com/spaces/SPACE/spaceNotificationSetting
. - The calling user's user ID. For example,
users/USER/spaces/SPACE/spaceNotificationSetting
.
- The
- The
notificationSetting
: sets the notification level, such asALL
,OFF
. - The
muteSetting
: sets the mute on or off, values can beMUTED
orUNMUTED
.
- The
updateMask
: sets the update fields, it can includenotification_setting
,mute_setting
.
The following example updates the calling user's space notification setting:
Node.js
To run this sample, replace SPACE_NAME
with the ID from
the space's
name
.
You can obtain the ID by calling the
ListSpaces()
method or from the space's URL.
The Google Chat API updates the specified space notification settings and returns
an instance of
SpaceNotificationSetting
.