## 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](https://developers.google.com/apps-script).

## Google APIs


### AdminSDK
- [Manage domains and apps](adminSDK)



### Advanced Services
- [Access Google APIs via Advanced Google services](advanced/)



### Calendar
- [List upcoming events](calendar/quickstart)
- [Create a vacation calendar](solutions/automations/vacation-calendar/Code.js)


### Classroom
- [Manage Google Classroom](classroom/quickstart)



### Data Studio
- [Build a connector](data-studio/build.gs)
- [Authentication and Authorization](data-studio/auth.gs)


### Docs
- [Cursor inspector add-on](docs/cursorInspector)
- [Translate add-on](docs/translate)


### Drive
- [Manage Google Drive files and folders](drive/quickstart)
- [View Google Drive activity](drive/activity)


### Forms
- [Notification add-on](forms)



### Gmail
- [Sending email](gmail/sendingEmails)
- [Mailmerge: Merge a template email with content](gmail/mailmerge)


### People
- [Listing Connections](people/quickstart)



### Sheets
- [Managing Responses for Google Forms](sheets)
- [Menus and Custom Functions](sheets)


### Slides
- [Translate Slides Add-on](slides/translate)
- [Progress Bars add-on](slides/progress)


### Tasks
- [List Tasks](tasks/quickstart)
- [Simple Tasks Web App](tasks/simpleTasks)


### Templates
- Build off a working framework for new Apps Script projects.



### Triggers
- Call an Apps Script function such as `onOpen`, `onEdit`, or `onInstall` in an add-on
- Create a [time-driven trigger](https://developers.google.com/apps-script/guides/triggers/installable#time_driven_triggers)

## 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](http://g.co/codelabs/apps-script-intro)
- [Apps Script CLI – clasp](http://g.co/codelabs/clasp)
- [BigQuery + Sheets + Slides](http://g.co/codelabs/bigquery-sheets-slides)
- [Docs Add-on + Cloud Natural Language API](http://g.co/codelabs/nlp-docs)
- [Gmail Add-ons](http://g.co/codelabs/gmail-add-ons)
- [Google Chat Apps](https://developers.google.com/codelabs/chat-apps-script)

## Clone using the `clasp` command-line tool

Learn how to clone, pull, and push Apps Script projects on the command-line
using [clasp](https://developers.google.com/apps-script/guides/clasp).

## Lint

Run ESLint over this whole repository with:

```shell
pnpm lint
```

This command will fix simple errors.

## Type Checking

Run the TypeScript-based check over the repository with:

```shell
pnpm check
```

This 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](https://developers.google.com/apps-script/guides/services/advanced#enabling_advanced_services) before running these samples.

Learn more at [developers.google.com](https://developers.google.com/apps-script/guides/services/advanced).

---

## 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

1. Create a Cloud Project
   1. Configure OAuth consent screen
   1. Enable the Admin SDK API
   1. Enable the Generative Language API
   1. Enable and configure the Google Chat API with the following values:
      1. App status: Live - available to users
      1. App name: “Standup”
      1. Avatar URL: “https://www.gstatic.com/images/branding/productlogos/chat_2020q4/v8/web-24dp/logo_chat_2020q4_color_2x_web_24dp.png”
      1. Description: “Standup App”
      1. Enable Interactive features: Disabled
1. Create a Google Gemini API Key 
   1. Navigate to https://aistudio.google.com/app/apikey 
   1. Create API key for existing project from step 1
   1. Copy the generated key 
1. Create and open a standalone Apps Script project
   1. From Project Settings, change project to GCP project number of Cloud Project from step 1
   1. Add the following script properties:
      1. Set `API_KEY` with the API key previously generated as the value.
      1. Set `SPREADSHEET_ID` with the file ID of a blank spreadsheet. 
      1. Set `SPACE_NAME` to the resource name of a Chat space (e.g. `spaces/AAAXYZ`)
   1. Enable the Google Chat advanced service
   1. Enable the AdminDirectory advanced service 
1. Add the project code to Apps Script
1. Enable triggers:
   1. Add Time-driven to run function `standup` at the desired interval frequency (e.g. Week timer)
   1. Add Time-driven to run function `summarize` at the desired interval frequency (e.g. Hour timer)

---

## 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

1. Create a Cloud Project
   1. Enable the Vertex AI API
   1. Create a Service Account and grant the role `Vertex AI User`
   1. Create a private key with type JSON. This will download the JSON file for use in the next section.
1. Open an Apps Script Project bound to a Google Sheets Spreadsheet
   1. From Project Settings, change project to GCP project number of Cloud Project from step 1
   1. Add a Script Property. Enter `service_account_key` as the property name and paste the JSON key from the service account as the value. 
1. Add OAuth2 v43 Apps Script Library using the ID `1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF`.
1. Add the project code to Apps Script

## Usage

1. Create a label in Gmail with this exact text and emojy (case sensitive!): UPSET TONE 😡
1. In Gmail, click on the Productivity toolbox icon (icon of a spy) in the sidepanel.
1. The sidepanel will open up. Grant the Add-on autorization to run.
1. The Add-on will load. Click on the blue button "Identify angry customers."
1. Close the Add-on by clicking on the X in the top right corner.
1. It can take a couple of minutes until the label is applied to the messages that have a negative tone.
1. 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

1. Create a Cloud Project
   1. Enable the Vertex AI API
   1. Enable Google Drive API
   1. Configure OAuth consent screen
   1. Create a Service Account and grant the role Service `Vertex AI User` role
   1. Create a private key with type JSON. This will download the JSON file for use in the next section.
1. Open a standalone Apps Script project.
   1. From Project Settings, change project to GCP project number of Cloud Project from step 1
   1. Add a Script Property. Enter `model_id` as the property name and `gemini-pro` as the value. 
   1. Add a Script Property. Enter `project_location` as the property name and `us-central1` as the value. 
   1. Add a Script Property. Enter `service_account_key` as the property name and paste the JSON key from the service account as the value. 
1. Add `Google Drive API v3` advanced service.
1. Add OAuth2 v43 Apps Script Library using the ID `1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF`.
1. 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

1. Create a Cloud Project
   1. Enable the Vertex AI API
   1. Create a Service Account and grant the role `Vertex AI User`
   1. Create a private key with type JSON. This will download the JSON file for use in the next section.
1. Open a stand alone Apps Script Project 
   1. From Project Settings, change project to GCP project number of Cloud Project from step 1
   1. Add a Script Property. Enter `service_account_key` as the property name and paste the JSON key from the service account as the value. 
1. Add OAuth2 v43 Apps Script Library using the ID `1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF`.
1. 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

1. Create a Cloud Project
   1. Enable Generative Language API - (may skip as is automatically done in step 2)
1. Create a Google Gemini API Key 
   1. Navigate to https://aistudio.google.com/app/apikey 
   1. Create API key for existing project from step 1
   1. Copy the generated key for use in the next step.
1. Open an Apps Script Project bound to a Google Sheets Spreadsheet
   1. From Project Settings, change project to GCP project number of Cloud Project from step 1
   1. Add a Script Property. Enter `api_key` as the property name and use the Gemini API Key as the value 
1. 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

1. Create a Cloud Project
   1. Enable the Vertex AI API
   1. Create a Service Account and grant the role `Vertex AI User`
   1. Create a private key with type JSON. This will download the JSON file for use in the next section.
1. Open an Apps Script Project bound to a Google Sheets Spreadsheet
   1. From Project Settings, change project to GCP project number of Cloud Project from step 1
   1. Add a Script Property. Enter `model_id` as the property name and `gemini-pro` as the value. 
   1. Add a Script Property. Enter `project_location` as the property name and `us-central1` as the value. 
   1. Add a Script Property. Enter `service_account_key` as the property name and paste the JSON key from the service account as the value. 
1. Add OAuth2 v43 Apps Script Library using the ID `1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF`.
1. 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


1. Create a Cloud Project
   1. Enable the Vertex AI API
   1. Create a Service Account and grant the role Service Account Token Creator Role
   1. Create a private key with type JSON. This will download the JSON file for use in the next section.
1. Open an Apps Script Project bound to a Google Sheets Spreadsheet.
   1. Rename the script to `Autosummarize AI`.
   1. From Project Settings, change project to GCP project number of Cloud Project from step 1
   1. Add a Script Property. Enter `model_id` as the property name and `gemini-pro-vision` as the value. 
   1. Add a Script Property. Enter `project_location` as the property name and `us-central1` as the value. 
   1. Add a Script Property. Enter `service_account_key` as the property name and paste the JSON key from the service account as the value. 
1. Add `OAuth2 v43` Apps Script Library using the ID `1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF`.
1. Enable the `Drive v3` advanced service.
1. Add the project code to Apps Script


## Usage

1. Insert one or more links to any Google Doc or Slides files in a column.
1. Select one or more of the links in the sheet.
1. From the `Sheets` menu, select `Extensions > AutoSummarize AI > Open AutoSummarize AI`
1. Click Get summaries button.

---

## File: chat/quickstart/README.md

# Google Chat Apps Script Quickstart

Complete the steps described in the [quickstart instructions](
https://developers.google.com/workspace/chat/api/guides/quickstart/apps-script),
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.