This page explains how to create an HTTP Chat app. There are different ways to implement this architecture. On Google Cloud, you can use Cloud Functions, Cloud Run, and App Engine. In this quickstart, you write and deploy a Cloud Function that the Chat app uses to respond to a user's message.
With this architecture, you configure Chat to integrate with Google Cloud or an on-premises server by using HTTP, as shown in the following diagram:
In the preceding diagram, a user interacting with an HTTP 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.
- An HTTP request is sent to a web server that is either a cloud or on-premises system that contains the Chat app logic.
- Optionally, the Chat app logic can integrate with Google Workspace services (like Calendar and Sheets), other Google services (like Maps, YouTube, and Vertex AI), or other web services (like a project management system or ticketing tool).
- The web server sends an HTTP response back to the Chat app service in Chat.
- The response is delivered to the user.
- Optionally, the Chat app can call the Chat API to asynchronously post messages or perform other operations.
This architecture provides you the flexibility to use existing libraries and components that already exist in your system because these Chat apps can be designed using different programming languages.
Objectives
- Set up your environment.
- Create and deploy a Cloud Function.
- Publish the app to Chat.
- Test the app.
Prerequisites
- A Google Workspace account with access to Google Chat in a Google Workspace organization that permits unauthenticated Google Cloud Function invocations.
- A Google Cloud project.
- Make sure that you turn on billing for your Cloud project. Learn how to verify the billing status of your projects.
Set up the environment
Before using Google APIs, you need to turn them on in a Google Cloud project. You can turn on one or more APIs in a single Google Cloud project.In the Google Cloud console, enable the Google Chat API, Cloud Build API, Cloud Functions API, Cloud Pub/Sub API, Cloud Logging API, Artifact Registry API, and Cloud Run API.
Create and deploy a Cloud Function
Create and deploy a Cloud Function that generates a Chat card with the sender's display name and avatar image. When the Chat app receives a message, it runs the function and responds with the card.
To create and deploy the function for your Chat app, complete the following steps:
Node.js
In the Google Cloud console, go to the Cloud Functions page:
Make sure that the project for your Chat app is selected.
Click
Create Function.On the Create function page, set up your function:
- In Environment, select 2nd gen.
- In Function name, enter
QuickStartChatApp
. - In Region, select a region.
- Under Authentication, select Allow unauthenticated invocations.
- Click Next.
In Runtime, select Node.js 20.
In Source code, select Inline Editor.
In Entry point, delete the default text and enter
helloChat
.Replace the contents of
index.js
with the following code:Click Deploy.
Python
In the Google Cloud console, go to the Cloud Functions page:
Make sure that the project for your Chat app is selected.
Click
Create Function.On the Create function page, set up your function:
- In Function name, enter
QuickStartChatApp
. - In Trigger type, select HTTP.
- Under Authentication, select Allow unauthenticated invocations.
- Click Save.
- Click Next.
- In Function name, enter
In Runtime, select Python 3.10.
In Source code, select Inline Editor.
In Entry point, delete the default text and enter
hello_chat
.Replace the contents of
main.py
with the following code:Click Deploy.
Java
In the Google Cloud console, go to the Cloud Functions page:
Make sure that the project for your Chat app is selected.
Click
Create Function.On the Create function page, set up your function:
- In Function name, enter
QuickStartChatApp
. - In Trigger type, select HTTP.
- Under Authentication, select Allow unauthenticated invocations.
- Click Save.
- Click Next.
- In Function name, enter
In Runtime, select Java 11.
In Source code, select Inline Editor.
In Entry point, delete the default text and enter
HelloChat
.Rename
src/main/java/com/example/Example.java
tosrc/main/java/HelloChat.java
.Replace the contents of
HelloChat.java
with the following code:Replace the contents of
pom.xml
with the following code:Click Deploy.
The Cloud Functions detail page opens, and your function appears with two progress indicators: one for the build and one for the service. When both progress indicators disappear and are replaced with a check mark, your function is deployed and ready.
Publish the app to Google Chat
After the Cloud Function is deployed, follow these steps to turn it into a Google Chat app:
In the Google Cloud console, click Menu > Cloud Functions.
Make sure that the project for which you enabled Cloud Functions is selected.
In the list of functions, click QuickStartChatApp.
On the Function details page, click Trigger.
Under Trigger URL, copy the URL.
Search for "Google Chat API" and click Google Chat API, then click Manage.
Click Configuration and set up the Google Chat app:
- In App name, enter
Quickstart App
. - In Avatar URL, enter
https://developers.google.com/chat/images/quickstart-app-avatar.png
. - In Description, enter
Quickstart app
. - Under Functionality, select Receive 1:1 messages and Join spaces and group conversations.
- Under Connection settings, select App URL and paste the URL for the Cloud Function trigger into the box.
- Under Visibility, select Make this Google Chat app available to specific people and groups in your domain and enter your email address.
- Under Logs, select Log errors to Logging.
- In App name, enter
Click Save.
The Chat app is ready to receive and respond to messages on Chat.
Test your Chat app
To test your Chat app, send the app a direct message:
- Open Google Chat.
- To send a direct message to the app, click Start a chat , and in the window that appears, click Find apps.
- In the Find apps dialog, search for
Quickstart App
. - To open a direct message with the app, find the Quickstart App and click Add > Chat.
- In the direct message, type
Hello
and pressenter
.
The Chat app's response contains a card message that displays the sender's name and avatar image, as demonstrated in the following image:
Troubleshoot errors
To troubleshoot and debug your Chat app, see Troubleshoot and fix Google Chat app errors.
Related topics
To add more features to your Chat app, see the following: