Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions studio/incoming-webhook-starter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Sqlite
*.sqlite
*.sqlite-shm
*.sqlite-wal

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.*
!.env.example

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist
.output

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp directory
.temp

# Sveltekit cache directory
.svelte-kit/

# vitepress build output
**/.vitepress/dist

# vitepress cache directory
**/.vitepress/cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# Firebase cache directory
.firebase/

# TernJS port file
.tern-port

# Stores Visual Studio Code versions used for testing Visual Studio Code extensions
.vscode-test

# pnpm
.pnpm-store

# yarn v3
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Vite files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
.vite/

# Astro generated types
.astro/

# Turbo Repo
.turbo

84 changes: 84 additions & 0 deletions studio/incoming-webhook-starter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Google Workspace Studio: Incoming Webhook Bridge Starter

This repository is a starter demo that demonstrates how to build an incoming webhook trigger for **Google Workspace Studio**.

It serves as a bridge between external services and your automated Workspace workflows. When an external tool (such as GitHub, Stripe, a monitoring service, or your own backend) sends an HTTP POST request to the webhook URL, this bridge receives the payload and triggers the corresponding workflow in Google Workspace Studio.

---

## What It Does

- **Provides a Webhook Endpoint**: Generates a dedicated webhook URL for each workflow you configure.
- **Connects External Systems**: Listens for incoming HTTP notifications and events from third-party tools.
- **Triggers Workspace Studio**: Validates incoming requests and immediately kicks off your Workspace Studio workflow with the event payload.

---

## What This Demo Demonstrates

- **Custom Triggers in Workspace Studio**: How to create and register custom triggers (like *"When a webhook is received"*) that appear natively in the Workspace Studio workflow builder.
- **Interactive Configuration Cards**: How to build in-editor cards where users can configure trigger options, authorize their account, and copy their generated webhook URL.
- **Account Authorization & Delegation**: How to handle Google authorization so the bridge can securely invoke Workspace Studio workflows on behalf of the user.
- **Optional Webhook Security**: How to support optional secret keys or API keys so only authorized callers can trigger the workflow.

---

## Getting Started

### Prerequisites

- [Node.js](https://nodejs.org/) (v20 or higher recommended)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/db/index.ts imports { DatabaseSync } from 'node:sqlite', which was introduced in Node.js v22.5.0 and does not exist in Node 20 (running on Node 20 fails immediately with ERR_UNKNOWN_BUILTIN_MODULE: node:sqlite).

Please update this prerequisite to Node.js v22.5.0 or higher (and consider adding "engines": { "node": ">=22.5.0" } to package.json).

Also, package.json runs node --env-file .env and .gitignore has !.env.example, but there is no .env.example in the repo and README.md doesn't document the required environment variables (GOOGLE_OAUTH_CLIENT_ID, GOOGLE_OAUTH_CLIENT_SECRET, GOOGLE_ADDON_SERVICE_ACCOUNT_EMAIL, GOOGLE_ADDON_CLIENT_ID, COOKIE_SECRET, PUBLIC_BASE_URL). Could we add a .env.example file and an environment setup section here?

- `npm` (comes with Node.js)

### 1. Install Dependencies

```bash
npm install
```

### 2. Database Generation & Setup

This demo uses SQLite to store trigger configurations and user credentials. Run the following commands to generate and push the database schema:

```bash
# Generate database migration files from schema
npm run db:generate

# Push schema changes to initialize your local SQLite database
npm run db:push
```

### 3. Build the Project

Compile the TypeScript code to JavaScript:

```bash
npm run build
```

### 4. Run the Project

- **Development Mode** (with auto-reload on file changes):
```bash
npm run dev
```
- **Production Mode** (after running `npm run build`):
```bash
npm run start
```
- **Run Tests**:
```bash
npm test
```

---

## Registering the Add-on (`deployment.json`)

The file `deployment.json` is a **deployment manifest template** used to register this add-on with Google Workspace:

1. **Host the application**: Deploy your server to a publicly reachable HTTPS host (such as Cloud Run, or use a tunneling tool like ngrok for local testing).
2. **Update the manifest template**: Open `deployment.json` and replace `DEPLOYED_HOST_NAME` with your actual domain (e.g., `https://your-service-url.run.app`).
3. **Register in Google Cloud**: Use this manifest when creating or updating your Google Workspace Add-on deployment in the Google Cloud Console.

Once deployed and installed, the webhook trigger will appear as an available starting step inside Google Workspace Studio.
58 changes: 58 additions & 0 deletions studio/incoming-webhook-starter/deployment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"oauthScopes": [
"openid",
"https://www.googleapis.com/auth/script.locale",
"https://www.googleapis.com/auth/workspace.studio.trigger"
],
"addOns": {
"common": {
"name": "Generic Incoming Webhook Bridge",
"logoUrl": "https://www.gstatic.com/images/icons/material/system/2x/webhook_black_48dp.png",
"useLocaleFromApp": true
},
"studio": {
"flows": {
"workflowElements": [
{
"id": "incoming_webhook_starter",
"state": "ACTIVE",
"name": "When a webhook is received",
"description": "Triggers the workflow when an arbitrary HTTP POST payload (up to 1 KB) is sent to your unique obfuscated webhook URL.",
"workflowTrigger": {
"onConfigFunction": "https://DEPLOYED_HOST_NAME/studio/on-config",
"onManageFunction": "https://DEPLOYED_HOST_NAME/studio/on-manage",
"inputs": [
{
"id": "instanceId",
"description": "Internal instance correlation UUID generated on configuration card load.",
"cardinality": "SINGLE",
"dataType": {
"basicType": "STRING"
}
},
{
"id": "requireApiKey",
"description": "Whether incoming webhook requests must provide an Authorization: ApiKey <secret> header.",
"cardinality": "SINGLE",
"dataType": {
"basicType": "BOOLEAN"
}
}
],
"outputs": [
{
"id": "rawPayload",
"description": "The raw UTF-8 payload string posted to the webhook URL (maximum 1 KB).",
"cardinality": "SINGLE",
"dataType": {
"basicType": "STRING"
}
}
]
}
}
]
}
}
}
}
10 changes: 10 additions & 0 deletions studio/incoming-webhook-starter/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
schema: './src/db/schema.ts',
out: './drizzle',
dialect: 'sqlite',
dbCredentials: {
url: process.env.DATABASE_URL || './webhook-bridge.sqlite',
},
});
Loading
Loading