Back

Google Chat API Essential Guide

Aug 2, 20246 minute read

What type of API does Google Chat provide?

Google Chat provides a REST API. The API is accessed via HTTP requests to the service endpoint chat.googleapis.com. It follows REST principles of using HTTP methods and endpoints to interact with resources like spaces, messages, members, and more.

Does the Google Chat API have webhooks?

Yes, the Google Chat API supports webhooks. These are primarily incoming webhooks that allow external applications to send messages into Google Chat spaces.

Key Points:

  • Webhooks are one-way communication channels for sending messages to Chat spaces.
  • They cannot receive or respond to messages from users.
  • Webhooks are not conversational and can't respond to Chat app interaction events.
  • They are registered for specific Chat spaces and only work in those spaces.
  • Webhooks can be used in direct messages when all users have Chat apps enabled.
  • They cannot be published to the Google Workspace Marketplace.

Implementation:

  1. Register the incoming webhook in the desired Chat space.
  2. Use the provided webhook URL to send HTTP POST requests with JSON payloads containing the message content.
  3. Messages can include text, formatted content, and interactive cards.

Security:

  • Keep webhook URLs confidential.
  • Follow Google Chat's recommendations for securing webhooks.

Best Practices:

  • Use webhooks for automated notifications, alerts, or updates from external systems.
  • Design messages to be timely, relevant, and actionable.
  • Consider message frequency and content to avoid overwhelming users.

For more complex interactions and event handling, developers should consider building full Chat apps that can respond to various interaction events.

Rate Limits and other limitations

Here are the key API rate limits for the Google Chat API:

Per-space Quotas

  • Reads per minute (shared among all Chat apps in the space): 900
  • Writes per minute (shared among all Chat apps in the space): 60

These limits apply to methods like media.download, spaces.get, spaces.messages.create, etc.

Per-project Quotas

Some key limits per project per 60 seconds:

  • Message writes: 3000
  • Message reads: 3000
  • Membership writes: 300
  • Membership reads: 3000
  • Space writes: 60
  • Space reads: 3000
  • Attachment writes: 600
  • Attachment reads: 3000
  • Reaction writes: 600
  • Reaction reads: 3000

Additional Limits

  • Creating spaces: Less than 35 per minute and 210 per hour for GROUP_CHAT or SPACE types
  • Large queries per second targeting the same space can trigger additional internal limits

Error Handling

If quotas are exceeded, you'll receive a 429 "Too Many Requests" HTTP status code. The recommended action is to use exponential backoff and retry later.

Key Points

  • There are separate per-space and per-project quotas
  • Most limits are per 60 second period
  • Exceeding quotas results in 429 errors
  • Exponential backoff should be used when hitting limits
  • Additional invisible limits may apply for high QPS to the same space

Best Practices

  • Stay within per-minute quotas to avoid daily limits
  • Use exponential backoff when receiving 429 errors
  • Consider requesting quota increases for per-project limits if needed
  • Be aware of additional limits on space creation

Latest API Version

The most recent version of the Google Chat API is v1. Here are the key points about the current state of the Google Chat API:

API Version

The Google Chat API is currently at version 1 (v1). This is the most up-to-date and stable version of the API.

Recent Updates and Features

  1. The API has received several updates and new features in recent months:

    • Import data from other messaging platforms into Google Chat (Generally available as of January 10, 2024).
    • Integration with Dialogflow CX for natural language understanding (Generally Available as of April 24, 2024).
    • Ability to make Chat spaces discoverable to specific users in a Google Workspace organization (Generally Available as of July 03, 2024).
  2. Some of the latest features include:

    • Sending private messages in multi-person spaces (Available since January 05, 2024).
    • Support for accessory widgets in messages (Generally available as of March 20, 2024).
    • Ability to send app home card messages (Generally available as of April 23, 2024).
  3. The API now supports various event subscriptions and operations:

    • Monitoring and receiving events about Google Chat spaces (Developer Preview as of October 03, 2023, Generally available as of March 28, 2024).
    • Subscribing to events for all Chat spaces where a user is a member (Available since June 24, 2024).

Best Practices

  1. When using the API, it's recommended to use the Google-provided client libraries.

  2. Keep up to date with the release notes to stay informed about new features and changes.

  3. For Node.js developers, the latest client library can be installed using npm install @google-apps/chat.

  4. The API supports the current active and maintenance versions of Node.js. It's recommended to use an actively supported LTS version.

Summary

The Google Chat API is continuously evolving with new features and improvements being added regularly. While the core API version remains at v1, developers should stay updated with the release notes to leverage the latest capabilities and ensure their applications are using the most recent features and best practices.

How to get a Google Chat developer account and API Keys?

To get a developer account for Google Chat and create an API integration, follow these steps:

  1. Create a Google Cloud project.

  2. Configure the OAuth consent screen for your project.

  3. Enable the Google Chat API for your project.

  4. In the Google Cloud console, search for "Google Chat API" and click on "Google Chat API", then click "Manage".

  5. Click the "Configuration" tab and enter the required information:

    • App name
    • Avatar URL
    • Description
  6. To enable interactive features, click the "Enable interactive features" toggle.

  7. Configure additional settings as needed:

    • Functionality
    • Connection settings
    • Slash commands
    • Link previews
    • Visibility
  8. Optionally, select the "Log errors to Logging" checkbox to log errors to Cloud Logging.

  9. Click "Save" to make your Chat app available to the specified users in your Google Workspace organization.

Key Points:

  • Ensure you have necessary permissions to create and configure a Google Cloud project and enable APIs.
  • Consider the functionality and permissions you grant to your Chat app carefully.
  • Test your app thoroughly before making it widely available.
  • Keep your app's credentials and sensitive information secure.

Best Practices:

  • Use a clear and descriptive name for your Chat app.
  • Provide a high-quality avatar image for better visibility.
  • Write a concise but informative description of your app's purpose.
  • Implement proper error handling and logging for easier troubleshooting.
  • Regularly update and maintain your app to ensure compatibility with any Google Chat API changes.

What can you do with the Google Chat API?

Based on the Google Chat API documentation, here are the key data models you can interact with using the API:

Spaces

  • Create, get, list, update, and delete spaces
  • Set up spaces by adding people and Chat apps
  • Find direct message (DM) spaces between users or between a user and a Chat app

Members

  • Create, get, list, update, and delete memberships in spaces
  • Add users or apps to spaces
  • Change member roles (e.g. from member to manager)

Messages

  • Create, get, list, update, and delete messages
  • Send messages privately
  • Format messages with text and cards
  • Archive messages

Attachments

  • Upload media as file attachments to messages
  • Download media attachments from messages
  • Get metadata about message attachments

Reactions

  • Add reactions to messages
  • List reactions on messages
  • Delete reactions from messages

Events

  • Get details about space events
  • List events from a space
  • Subscribe to events using the Google Workspace Events API

User Read States

  • Get and update a user's read state within a space
  • Get a user's read state within a message thread

Media

  • Represents files uploaded to Google Chat like images, videos, documents

Key points:

  • The API allows both synchronous and asynchronous interactions
  • Authentication is required for asynchronous API calls
  • Different methods require either user or app authentication
  • The API provides comprehensive CRUD operations on most resources
  • You can build interactive experiences using cards, dialogs, and slash commands