File: README.md
Google Apps Script Samples
Various sample code and projects for the Google Apps Script platform, a JavaScript platform in the cloud.
Learn more at developers.google.com.
Google APIs
AdminSDK
Advanced Services
Calendar
Classroom
Data Studio
Docs
Drive
Forms
Gmail
People
Sheets
Slides
Tasks
Templates
- Build off a working framework for new Apps Script projects.
Triggers
- Call an Apps Script function such as
onOpen,onEdit, oronInstallin an add-on - Create a time-driven trigger
Codelabs
Codelab tutorials combine detailed explanation, coding exercises, and documented best practices to help engineers get up to speed with key Google technologies. Here's a list of Apps Script codelabs:
- Apps Script Intro
- Apps Script CLI โ clasp
- BigQuery + Sheets + Slides
- Docs Add-on + Cloud Natural Language API
- Gmail Add-ons
- Google Chat Apps
Clone using the `clasp` command-line tool
Learn how to clone, pull, and push Apps Script projects on the command-line
using clasp.
Lint
Run ESLint over this whole repository with:
pnpm lintThis command will fix simple errors.
Type Checking
Run the TypeScript-based check over the repository with:
pnpm checkThis command validates .gs files by temporarily converting them to .js and running tsc. It checks for syntax errors and type issues using JSDoc annotations.
File: advanced/README.md
Advanced Services Samples
This directory contains samples for using Apps Script Advanced Services.
Note: These services must be enabled before running these samples.
Learn more at developers.google.com.
File: ai/standup-chat-app/README.md
Chat API - Stand up with AI
Project Description
Google Chat application that creates AI summaries of a consolidation Chat threads and posts them back within the top-level Chat message. Use case is using AI to streamline Stand up content within Google Chat.
Prerequisites
- Google Cloud Project (aka Standard Cloud Project for Apps Script) with billing enabled
Set up your environment
- Create a Cloud Project
- Configure OAuth consent screen
- Enable the Admin SDK API
- Enable the Generative Language API
- Enable and configure the Google Chat API with the following values:
- App status: Live - available to users
- App name: โStandupโ
- Avatar URL: โhttps://www.gstatic.com/images/branding/productlogos/chat_2020q4/v8/web-24dp/logo_chat_2020q4_color_2x_web_24dp.pngโ
- Description: โStandup Appโ
- Enable Interactive features: Disabled
- Create a Google Gemini API Key
- Navigate to https://aistudio.google.com/app/apikey
- Create API key for existing project from step 1
- Copy the generated key
- Create and open a standalone Apps Script project
- From Project Settings, change project to GCP project number of Cloud Project from step 1
- Add the following script properties:
- Set
API_KEYwith the API key previously generated as the value. - Set
SPREADSHEET_IDwith the file ID of a blank spreadsheet. - Set
SPACE_NAMEto the resource name of a Chat space (e.g.spaces/AAAXYZ)
- Set
- Enable the Google Chat advanced service
- Enable the AdminDirectory advanced service
- Add the project code to Apps Script
- Enable triggers:
- Add Time-driven to run function
standupat the desired interval frequency (e.g. Week timer) - Add Time-driven to run function
summarizeat the desired interval frequency (e.g. Hour timer)
- Add Time-driven to run function
File: ai/gmail-sentiment-analysis/README.md
Gmail sentiment analysis with Vertex AI
Project Description
Google Workspace Add-on that extends Gmail and adds sentiment analysis capabilities.
Prerequisites
- Google Cloud Project (aka Standard Cloud Project for Apps Script) with billing enabled
Set up your environment
- Create a Cloud Project
- Enable the Vertex AI API
- Create a Service Account and grant the role
Vertex AI User - Create a private key with type JSON. This will download the JSON file for use in the next section.
- Open an Apps Script Project bound to a Google Sheets Spreadsheet
- From Project Settings, change project to GCP project number of Cloud Project from step 1
- Add a Script Property. Enter
service_account_keyas the property name and paste the JSON key from the service account as the value.
- Add OAuth2 v43 Apps Script Library using the ID
1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF. - Add the project code to Apps Script
Usage
- Create a label in Gmail with this exact text and emojy (case sensitive!): UPSET TONE ๐ก
- In Gmail, click on the Productivity toolbox icon (icon of a spy) in the sidepanel.
- The sidepanel will open up. Grant the Add-on autorization to run.
- The Add-on will load. Click on the blue button "Identify angry customers."
- Close the Add-on by clicking on the X in the top right corner.
- It can take a couple of minutes until the label is applied to the messages that have a negative tone.
- If you don't want to wait until the labels are added, you can refresh the browser.
File: ai/drive-rename/README.md
Google Workspace Add-on Drive - Name with Intelligence
Project Description
Google Workspace Add-on for Google Drive, which uses AI to recommend new names for the selected Doc in Google Drive by passing the body of the document within the AI prompt for context.
Prerequisites
- Google Cloud Project (aka Standard Cloud Project for Apps Script) with billing enabled
Set up your environment
- Create a Cloud Project
- Enable the Vertex AI API
- Enable Google Drive API
- Configure OAuth consent screen
- Create a Service Account and grant the role Service
Vertex AI Userrole - Create a private key with type JSON. This will download the JSON file for use in the next section.
- Open a standalone Apps Script project.
- From Project Settings, change project to GCP project number of Cloud Project from step 1
- Add a Script Property. Enter
model_idas the property name andgemini-proas the value. - Add a Script Property. Enter
project_locationas the property name andus-central1as the value. - Add a Script Property. Enter
service_account_keyas the property name and paste the JSON key from the service account as the value.
- Add
Google Drive API v3advanced service. - Add OAuth2 v43 Apps Script Library using the ID
1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF. - Add the project code to Apps Script
File: ai/devdocs-link-preview/README.md
Google Workspace Add-on - Developer Docs Link previews
Project Description
A Google Workspace Add-on that creates custom link previews for pages on the Google developer documentation site. The link preview uses AI to generate page summaries.
Prerequisites
- Google Cloud Project (aka Standard Cloud Project for Apps Script) with billing enabled
Set up your environment
- Create a Cloud Project
- Enable the Vertex AI API
- Create a Service Account and grant the role
Vertex AI User - Create a private key with type JSON. This will download the JSON file for use in the next section.
- Open a stand alone Apps Script Project
- From Project Settings, change project to GCP project number of Cloud Project from step 1
- Add a Script Property. Enter
service_account_keyas the property name and paste the JSON key from the service account as the value.
- Add OAuth2 v43 Apps Script Library using the ID
1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF. - Add the project code to Apps Script
File: ai/custom-func-ai-studio/README.md
Google Sheets Custom Function with AI Studio
Project Description
Google Sheets Custom Function to be used as a bound Apps Script project with a Google Sheets Spreadsheet
Prerequisites
- Google Cloud Project (aka Standard Cloud Project for Apps Script) with billing enabled
Set up your environment
- Create a Cloud Project
- Enable Generative Language API - (may skip as is automatically done in step 2)
- Create a Google Gemini API Key
- Navigate to https://aistudio.google.com/app/apikey
- Create API key for existing project from step 1
- Copy the generated key for use in the next step.
- Open an Apps Script Project bound to a Google Sheets Spreadsheet
- From Project Settings, change project to GCP project number of Cloud Project from step 1
- Add a Script Property. Enter
api_keyas the property name and use the Gemini API Key as the value
- Add the project code to Apps Script
Usage
Insert a custom function in Google Sheets, passing a range and a prompt as parameters
Example:
=gemini(A1:A10,"Extract colors from the product description")File: ai/custom_func_vertex/README.md
Google Sheets Custom Function with AI Studio
Project Description
Google Sheets Custom Function to be used as a bound Apps Script project with a Google Sheets Spreadsheet.
Prerequisites
- Google Cloud Project (aka Standard Cloud Project for Apps Script) with billing enabled
Set up your environment
- Create a Cloud Project
- Enable the Vertex AI API
- Create a Service Account and grant the role
Vertex AI User - Create a private key with type JSON. This will download the JSON file for use in the next section.
- Open an Apps Script Project bound to a Google Sheets Spreadsheet
- From Project Settings, change project to GCP project number of Cloud Project from step 1
- Add a Script Property. Enter
model_idas the property name andgemini-proas the value. - Add a Script Property. Enter
project_locationas the property name andus-central1as the value. - Add a Script Property. Enter
service_account_keyas the property name and paste the JSON key from the service account as the value.
- Add OAuth2 v43 Apps Script Library using the ID
1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF. - Add the project code to Apps Script
Usage
Insert a custom function in Google Sheets, passing a range and a prompt as parameters
Example:
=gemini(A1:A10,"Extract colors from the product description")File: ai/autosummarize/README.md
Editor Add-on: Sheets - AutoSummarize AI
Project Description
Google Workspace Editor Add-on for Google Sheets that uses AI to create AI summaries in bulk for a listing of Google Docs and Slides files.
Prerequisites
- Google Cloud Project (aka Standard Cloud Project for Apps Script) with billing enabled
Set up your environment
- Create a Cloud Project
- Enable the Vertex AI API
- Create a Service Account and grant the role Service Account Token Creator Role
- Create a private key with type JSON. This will download the JSON file for use in the next section.
- Open an Apps Script Project bound to a Google Sheets Spreadsheet.
- Rename the script to
Autosummarize AI. - From Project Settings, change project to GCP project number of Cloud Project from step 1
- Add a Script Property. Enter
model_idas the property name andgemini-pro-visionas the value. - Add a Script Property. Enter
project_locationas the property name andus-central1as the value. - Add a Script Property. Enter
service_account_keyas the property name and paste the JSON key from the service account as the value.
- Rename the script to
- Add
OAuth2 v43Apps Script Library using the ID1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF. - Enable the
Drive v3advanced service. - Add the project code to Apps Script
Usage
- Insert one or more links to any Google Doc or Slides files in a column.
- Select one or more of the links in the sheet.
- From the
Sheetsmenu, selectExtensions > AutoSummarize AI > Open AutoSummarize AI - Click Get summaries button.
File: chat/quickstart/README.md
Google Chat Apps Script Quickstart
Complete the steps described in the quickstart instructions,
and in about five minutes you'll have a simple Apps Script application
that makes requests to the Google Chat API.
Run
After following the quickstart setup instructions, execute the function listSpaces
from the Apps Script console.