
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create a chat app from a template
/ 50
Configure the user consent screen
/ 50
Google Chat bots provide easy-to-use access points to your organization's data and services. Users can converse with bots within a chat experience. One way to create a Google Chat bot is to use Google Apps Script. This also gives you easy access to other Google services like Drive, Gmail, Calendar, Docs, Sheets, and much more.
In this lab, you use Google Apps Script to create a simple Google Chat bot as a quick introduction to Google Chat bots.
In this lab, you perform the following tasks:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
To implement your bot, create a new Google Apps Script project using the Chat app template.
Click this Google Apps Script homepage link to open the Google Apps Script online editor.
Under Google Workspace add-on starters, click Chat app (Intermediate version).
Click Untitled project (the current name).
In the Edit project name dialog, rename the project to Friendly Bot
, and then click Rename.
Most Apps Script bot interactions with Google Chat are event-driven. The interaction between the user, the bot, and Google Chat typically follows a sequence.
Google Chat raises four events that your Apps Script bot can listen for:
ADDED_TO_SPACE
: This event occurs when a human user adds a bot to a room or a DM. In Apps Script, you define an onAddedToSpace()
function to handle this event.REMOVED_FROM_SPACE
: This event occurs when a user removes the bot from a room or DM. This event does not post a response back to Google Chat. In Apps Script, you define an onRemovedFromSpace()
function to handle this event.MESSAGE
: This event occurs when a user messages the bot, either directly in a DM or as an @mention in a room. In Apps Script, you define an onMessage()
function to respond to this event.MESSAGE
event handlerThe Chat App template pre-populates the code file containing the event handlers.
Code.gs
file to review the pre-populated event handlers.Notice the event handlers for the MESSAGE
, ADDED_TO_SPACE
and REMOVE_FROM_SPACE
events, which execute the specific functions previously mentioned to complete various tasks such as responding to user messages in Google Chat.
Before you can run and test the bot, the Google Chat API must be enabled for your Google Cloud project, and your bot must be published.
In this task, you complete the various configuration steps to be able to publish the bot including configuring the OAuth consent screen, updating the Apps Script application to reference the appropriate Google Cloud project, and updating the Google Chat API configuration to publish the bot for testing.
In the Google Cloud console, click the Navigation menu () in the upper left, and navigate to APIs & Services > OAuth consent screen.
Click Get Started.
For Project configuration page, for App Information configure the following, and then click Next:
Field | Value |
---|---|
App name | Friendly Bot |
User support email | Select the email ID |
For Audience, select Internal and click Next.
For Contact Information, provide the email address
Accept the policy, and click Continue. Then, click Create.
Click Check my progress to verify the objective.
From the Navigation menu (), click Cloud Overview > Dashboard.
In the dashboard, locate the Project Info section.
Record the Project number to use in the next step to configure your project.
Return to the Apps Script editor, and navigate to the Project Settings for the Friendly Bot project ().
Under Google Cloud Platform (GCP) Project, click Change project.
For GCP Project number, enter the project number that you copied earlier. Then, click Set project.
In the Apps Script editor, get the Head Deployment ID for the test deployment by clicking on Deploy > Test Deployments (top-right of the screen), and then clicking Copy next to Head Deployment ID.
In the Google Cloud console, navigate to Navigation Menu () > APIs & Services > Library.
In the Library, search for Google Chat API
, and select the API from the list of results.
The Google Chat API should already be enabled in this project. If it is not enabled, click Enable.
Click Manage, and then click the Configuration tab for the Google Chat API.
In the Configuration dialog, set the fields with the following values:
Field | Value |
---|---|
App name | Friendly Bot |
Avatar URL | https://goo.gl/kv2ENA |
Description | Apps Script lab bot |
Functionality | Enable Join spaces and group conversations |
Connection settings | Check Apps Script, and then paste the Head Deployment ID that you copied in step 1 into the Deployment ID box. |
Visibility |
Click Save.
After the changes are saved, scroll to the top of the Configuration dialog to update the App Status to LIVE – available to users
.
You may have to refresh the page to see the App Status field. If the value for App Status is already set to LIVE – available to users
, you can leave that value, but be sure to save the page again in the next step.
You have made it to final section to test your bot in Google Chat by completing the following steps!
Click the Google Chat link to open Google Chat.
Select Start a chat.
Search for Friendly bot
.
From the results, select the Friendly Bot (Apps Script lab bot) that you created to start a chat.
When the direct message thread opens, you should see a message from the bot thanking you for adding it to a DM:
Thank you for adding me to a direct message, student XXXXX!
This response is initiated by the function named onAddedToSpace
, which responds to the specific event of the bot being added to a chat space.
You should see a message from the bot repeating your message, such as:
You said "Hello bot!"
This response is initiated by the function named onMessage
, which responds to the specific event of users direct messaging the bot.
You quickly created a Google Chat bot that responds to user messages!
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated August 18, 2025
Lab Last Tested August 18, 2025
Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one