Get details about a Google Chat space event

This guide explains how to use the get() method on the SpaceEvent resource of the Google Chat API to get details about an event from a Google Chat space.

The SpaceEvent resource represents a change to a space or its child resources, such as messages, reactions, and memberships. To learn about the supported event types, see the eventType field of the SpaceEvent resource reference documentation.

You can request events up to 28 days before the time of the request. The event contains the most recent version of the resource that changed. For example, if you request an event about a new message but the message was later updated, the server returns the updated Message resource in the event payload.

To call this method, you must use user authentication. To get an event, the authenticated user must be a member of the space where the event occurred.

Prerequisites

Node.js

Get details about a space event

To get details about a space event in Google Chat, pass the following in your request:

  • Specify an authorization scope that supports the event type in your request. As a best practice, choose the most restrictive scope that still allows your app to function.
  • Call the GetSpaceEvent() method, passing the name of the space event to get.

The following example gets a space event:

Node.js

chat/client-libraries/cloud/get-space-event-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';

// Replace SCOPE_NAME here with an authorization scope based on the event type
const USER_AUTH_OAUTH_SCOPES = ['SCOPE_NAME'];

// This sample shows how to get space event with user credential
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);

  // Initialize request argument(s)
  const request = {
    // Replace SPACE_NAME and SPACE_EVENT_NAME here
    name: 'spaces/SPACE_NAME/spaceEvents/SPACE_EVENT_NAME'
  };

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

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

main().catch(console.error);

To run this sample, replace the following:

  • SCOPE_NAME: an authorization scope based on the event type. For example, if you are getting a space event about a new membership, use the chat.memberships.readonly scope, formatted as https://www.googleapis.com/auth/chat.memberships.readonly. You can obtain the event type from the ListSpaceEvents() method. To learn how to use this method, see List events from a space.
  • SPACE_NAME: the ID from the space's name. You can obtain the ID by calling the ListSpaces() method or from the space's URL.
  • SPACE_EVENT_NAME: the ID from the space event's name. You can obtain the ID from the ListSpaceEvents() method. To learn how to use this method, see List events from a space.

The Chat API returns an instance of SpaceEvent with details about the event.