Complete the following steps to create a simple Google Chat bot. The bot can be directly messaged, and responds by echoing your messages.
To run this quickstart, you need:
A Google Cloud project with the API enabled. To create a project and enable an API, refer to Create a project and enable the API.
A Google Cloud project with the OAuth consent screen configured. To configure the OAuth consent screen, refer to Configure the OAuth consent screen.
Step 1: Create the script
- Create the script from the Chat bot template.
- Go to the Apps Script Getting Started page.
- Click the Chat Bot template. You might have to scroll down to see this template.
- Click Untitled project at the top left, type
Quickstart bot, and click Rename.
- Copy the Google Cloud project number.
- Open the Google Cloud Console.
- If necessary, open the Google Cloud project you intend to use for this quickstart:
- Next to "Google Cloud Platform," click the Down arrow . A dialog listing current projects appears.
- Select your project and click Open. The console opens your project.
- In the upper-right corner, click Settings and Utilities > Project settings.
- Copy the Project number.
- Set the Apps Script project's Google Cloud project.
- Return to the Chat bot Apps Script project.
- At the left, 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.
- Open the Google Apps Script Editor using the Chat bot template.
- Click File > Save, name the project "Quickstart bot", and click OK.
You now have working bot code that you can try out (as described in the steps below) and then customize to meet your requirements.
Be sure you're signed in to the correct Google account when you open the Apps Script template. The current account can sometimes be switched to your default account without your noticing.
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:
- Click Deploy > New deployment.
- Under Select type, click Add-on.
- Fill out the options and click Deploy.
- Under "Deployment ID," click Copy.
- Click Publish > Deploy from manifest.
- In the Deployments dialog box next to Latest Version (HEAD), click Get ID.
- In the Deployment ID dialog box, copy the value listed for the Deployment ID.
- Click Close and Close to dismiss the dialog boxes.
Step 2: Publish the bot
Publish the Chat bot from Google Cloud Console.
- Open the Google Cloud Console.
Search for "Google Chat API" and click Google Chat API.
- Click Manage.
Click Configuration and set up the Google Chat bot:
In the Bot name field, enter
In the Avatar URL field, enter
In the Description field, enter
Under Functionality, select Bot can be messaged directly.
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 own email.
The Chat bot is ready to respond to messages.
Step 3: Run the sample
To run the sample, do the following:
- Open Google Chat.
- Send a new direct message to the bot by clicking Start a chat > Find a bot.
- On the Find a bot page, search for "Quickstart Bot".
- Next to Quickstart Bot, click Chat.
- In the new direct message with the bot, type
The bot thanks you for adding it and echoes your message.
To add more functionality to your Chat bot, refer to these guides:
- 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 bot by typing a command that begins with a forward slash (
- Launch dialogs — Dialogs are windowed, card-based interfaces that your bot 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.