Create a Google Chat app that you can directly message and that responds by echoing your messages.
- Set up your environment.
- Create the script.
- Publish the app.
- Run the sample.
- A Google Workspace account with access to Chat.
- A Google Cloud project.
- A Cloud project with the OAuth consent screen configured.
Set up your environment
To complete this quickstart, set up your environment.
Enable the APIBefore using Google APIs, you need to enable them in a Google Cloud project. You can enable one or more APIs in a single Google Cloud project.
In the Google Cloud console, enable the Google Chat API.
Configure a Cloud project with the OAuth consent screen
All apps using OAuth 2.0 require a consent screen configuration. Configuring your app's OAuth consent screen defines what is displayed to users and app reviewers, and registers your app so you can publish it later.
- In the Google Cloud console, go to Menu > APIs & Services > OAuth consent screen.
- Select the user type for your app, then click Create.
- Complete the app registration form, then click Save and Continue.
If you're creating an app for use outside of your Google Workspace organization, click Add or Remove Scopes. Add and verify the authorization scopes required by your app, then click Save and Continue.
Some scopes require additional reviews by Google. For apps used only internally by your Google Workspace organization, scopes aren't listed on the consent screen and use of restricted or sensitive scopes does not require further review by Google. For more details, see How to choose scopes for your app.
- Under Test users, click Add users.
- Enter your email address and any other authorized test users, then click Save and Continue.
- Review your app registration summary. To make changes, click Edit. If the app registration looks OK, click Back to Dashboard.
Create the script
To create the script, you use a template and then set your Cloud project in Apps Script.
Create the script from the template
- Go to the Apps Script Getting Started page.
- Click the Chat App template. You might have to scroll down to see this template.
- Click Untitled project, type
Quickstart app, and click Rename.
Copy the Cloud project number
- Go to the Google Cloud console.
- If necessary, open the Cloud project that you intend to use for
- Next to Google Cloud, click the Down arrow . A dialog listing current projects appears.
- Select your project and click Open. The console opens your project.
- Click Settings and Utilities > Project settings.
- Copy the Project number.
Set the Apps Script project's Cloud project
- In the Chat app Apps Script project, click Project Settings .
- Under Google Cloud Platform (GCP) Project, click Change project.
- In GCP project number, paste the Google Cloud project number.
- Click Set project.
You now have working app code that you can try out (as described in the following steps) and then customize to meet your requirements.
Make sure that you're signed in to the correct Google Account when you open the Apps Script template. The current account can sometimes switch to your default account without you noticing.
Get the Deployment ID
You need the Deployment ID for this Apps Script project, so that you can use it in the next step.
To get the Deployment ID, do the following:
- In the Chat app Apps Script project, click Deploy > New deployment.
- Under Select type, click Add-on.
- Fill out the options and click Deploy.
- Under Deployment ID, click Copy.
Publish the Chat app
Publish the Chat app from the Google Cloud console.
- In the
Google Cloud console,
Google Chat API, and click Google Chat API.
- Click Manage.
Click Configuration and set up the Chat app:
- In the App name field, enter
- In the Avatar URL field, enter
- In the Description field, enter
- Under Functionality, select Receive 1:1 messages and Join spaces and group conversations.
- Under Connection settings, select Apps Script project and paste the Deployment ID into the field.
- Under Permissions, select Specific people and groups in your domain, and enter your email.
- In the App name field, enter
The Chat app is ready to respond to messages.
Run the sample
- Open Chat.
- Send a new direct message to the app by clicking Start a chat > Find apps.
- On the Find apps page, search for "Quickstart App".
- Next to Quickstart App, click Chat.
- In the new direct message with the app, type
The app thanks you for adding it and echoes your message.
- Create interactive cards. Card messages support a defined layout, interactive UI elements like buttons, and rich media like images. Use card messages to present detailed information, gather information from users, and guide users to take a next step.
- Support slash commands. Slash commands let
you register and advertise specific commands that users can give your app
by typing a command that begins with a forward slash (
- Launch dialogs. Dialogs are windowed, card-based interfaces that your app can open to interact with a user. Multiple cards can be strung together sequentially, which helps users complete multi-step processes, like filling in form data.