--- name: google-workspace description: Gmail, Calendar, Drive, Contacts, Sheets, and Docs integration via gws CLI (googleworkspace/cli). Uses OAuth2 with automatic token refresh via bridge script. Requires gws binary. version: 2.0.0 author: Nous Research license: MIT required_credential_files: - path: google_token.json description: Google OAuth2 token (created by setup script) - path: google_client_secret.json description: Google OAuth2 client credentials (downloaded from Google Cloud Console) metadata: hermes: tags: [Google, Gmail, Calendar, Drive, Sheets, Docs, Contacts, Email, OAuth, gws] homepage: https://github.com/NousResearch/hermes-agent related_skills: [himalaya] --- # Google Workspace Gmail, Calendar, Drive, Contacts, Sheets, and Docs — powered by `gws` (Google's official Rust CLI). The skill provides a backward-compatible Python wrapper that handles OAuth token refresh and delegates to `gws`. ## Architecture ``` google_api.py → gws_bridge.py → gws CLI (argparse compat) (token refresh) (Google APIs) ``` - `setup.py` handles OAuth2 (headless-compatible, works on CLI/Telegram/Discord) - `gws_bridge.py` refreshes the Hermes token and injects it into `gws` via `GOOGLE_WORKSPACE_CLI_TOKEN` - `google_api.py` provides the same CLI interface as v1 but delegates to `gws` ## References - `references/gmail-search-syntax.md` — Gmail search operators (is:unread, from:, newer_than:, etc.) ## Scripts - `scripts/setup.py` — OAuth2 setup (run once to authorize) - `scripts/gws_bridge.py` — Token refresh bridge to gws CLI - `scripts/google_api.py` — Backward-compatible API wrapper (delegates to gws) ## Prerequisites Install `gws`: ```bash cargo install google-workspace-cli # or via npm (recommended, downloads prebuilt binary): npm install -g @googleworkspace/cli # or via Homebrew: brew install googleworkspace-cli ``` Verify: `gws --version` ## First-Time Setup The setup is fully non-interactive — you drive it step by step so it works on CLI, Telegram, Discord, or any platform. Define a shorthand first: ```bash HERMES_HOME="${HERMES_HOME:-$HOME/.hermes}" GWORKSPACE_SKILL_DIR="$HERMES_HOME/skills/productivity/google-workspace" PYTHON_BIN="${HERMES_PYTHON:-python3}" if [ -x "$HERMES_HOME/hermes-agent/venv/bin/python" ]; then PYTHON_BIN="$HERMES_HOME/hermes-agent/venv/bin/python" fi GSETUP="$PYTHON_BIN $GWORKSPACE_SKILL_DIR/scripts/setup.py" ``` ### Step 0: Check if already set up ```bash $GSETUP --check ``` If it prints `AUTHENTICATED`, skip to Usage — setup is already done. ### Step 1: Triage — ask the user what they need **Question 1: "What Google services do you need? Just email, or also Calendar/Drive/Sheets/Docs?"** - **Email only** → Use the `himalaya` skill instead — simpler setup. - **Calendar, Drive, Sheets, Docs (or email + these)** → Continue below. **Partial scopes**: Users can authorize only a subset of services. The setup script accepts partial scopes and warns about missing ones. **Question 2: "Does your Google account use Advanced Protection?"** - **No / Not sure** → Normal setup. - **Yes** → Workspace admin must add the OAuth client ID to allowed apps first. ### Step 2: Create OAuth credentials (one-time, ~5 minutes) Tell the user: > 1. Go to https://console.cloud.google.com/apis/credentials > 2. Create a project (or use an existing one) > 3. Enable the APIs you need (Gmail, Calendar, Drive, Sheets, Docs, People) > 4. Credentials → Create Credentials → OAuth 2.0 Client ID → Desktop app > 5. Download JSON and tell me the file path ```bash $GSETUP --client-secret /path/to/client_secret.json ``` ### Step 3: Get authorization URL ```bash $GSETUP --auth-url ``` Send the URL to the user. After authorizing, they paste back the redirect URL or code. ### Step 4: Exchange the code ```bash $GSETUP --auth-code "THE_URL_OR_CODE_THE_USER_PASTED" ``` ### Step 5: Verify ```bash $GSETUP --check ``` Should print `AUTHENTICATED`. Token refreshes automatically from now on. ## Usage All commands go through the API script: ```bash HERMES_HOME="${HERMES_HOME:-$HOME/.hermes}" GWORKSPACE_SKILL_DIR="$HERMES_HOME/skills/productivity/google-workspace" PYTHON_BIN="${HERMES_PYTHON:-python3}" if [ -x "$HERMES_HOME/hermes-agent/venv/bin/python" ]; then PYTHON_BIN="$HERMES_HOME/hermes-agent/venv/bin/python" fi GAPI="$PYTHON_BIN $GWORKSPACE_SKILL_DIR/scripts/google_api.py" ``` ### Gmail ```bash $GAPI gmail search "is:unread" --max 10 $GAPI gmail get MESSAGE_ID $GAPI gmail send --to user@example.com --subject "Hello" --body "Message text" $GAPI gmail send --to user@example.com --subject "Report" --body "