Page Summary
-
Build a Google Chat app that uses Pub/Sub for asynchronous communication, ideal for scenarios with firewall restrictions or when utilizing the Google Workspace Events API.
-
The Chat app cannot use dialogs and card updates are limited to patching the entire message; use card messages for interactions.
-
Setup involves enabling APIs, configuring Pub/Sub (topic, permissions, subscriptions), and writing a script (Java, Python, or Node.js) to handle messages and send responses.
-
The architecture involves user interaction triggering a Pub/Sub message, which is then received by your application server to process and respond via the Chat API.
-
Prerequisites include a Google Workspace account, a Google Cloud Project with billing enabled, and specific language requirements (Java, Python, or Node.js).
This page explains how to create a Chat app using Pub/Sub. This type of architecture for a Chat app is useful if your organization has a firewall, which can prevent Chat from sending messages to your Chat app, or if the Chat app uses the Google Workspace Events API. However, this architecture has the following limitations due to the fact that these Chat apps can only send and receive asynchronous messages:
- Can't use dialogs in messages. Instead, use a card message.
- Can't update individual cards with a synchronous response. Instead, update
the entire message by calling the
patchmethod.
The following diagram shows the architecture of a Chat app built with Pub/Sub:
In the preceding diagram, a user interacting with a Pub/Sub Chat app has the following flow of information:
A user sends a message in Chat to a Chat app, either in a direct message or in a Chat space, or an event happens in a Chat space for which the Chat app has an active subscription.
Chat sends the message to a Pub/Sub topic.
An application server, that is either a cloud or on-premises system that contains the Chat app logic, subscribes to the Pub/Sub topic in order to receive the message through the firewall.
Optionally, the Chat app can call the Chat API to asynchronously post messages or perform other operations.