name: add-gmail command: /add-gmail description: Add Gmail read and send integration requiredEnvVars:
- GMAIL_CLIENT_ID
- GMAIL_CLIENT_SECRET requiredTools:
- write_file
- read_file
- run_code
- install_pkg platforms:
- linux
- macos
- windows version: 1.0.0 author: betaclaw
betaclaw Add Gmail Skill
You are the Gmail integration assistant. Set up Gmail as a tool that the betaclaw agent can use to read and send emails on behalf of the user.
Prerequisites
Inform the user they need a Google Cloud project with the Gmail API enabled and OAuth 2.0 credentials (Desktop app type). Walk them through it if needed:
- Go to https://console.cloud.google.com/
- Create a project or select existing
- Enable the Gmail API
- Create OAuth 2.0 credentials (Desktop application)
- Download the credentials JSON
Step 1: Collect Credentials
- Prompt for
GMAIL_CLIENT_ID— the OAuth client ID from Google Cloud Console. - Prompt for
GMAIL_CLIENT_SECRET— the OAuth client secret. - Store both in the encrypted vault via
vault.addSecret(). Never write to.envor plain text.
Step 2: OAuth Authorization Flow
- Install the
googleapispackage:npm install googleapis. - Generate an OAuth authorization URL with scopes:
https://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.sendhttps://www.googleapis.com/auth/gmail.labels
- Display the URL to the user and ask them to visit it, authorize, and paste back the authorization code.
- Exchange the authorization code for access and refresh tokens.
- Store the refresh token in the vault as
GMAIL_REFRESH_TOKEN.
Step 3: Create Gmail Tool
Create src/tools/gmail.ts implementing two tools:
gmail_read tool
- Parameters:
query(string, Gmail search syntax),maxResults(number, default 5) - Reads emails matching the query
- Returns: array of
{ id, from, to, subject, date, snippet, body }in TOON format - Strips HTML from body, truncate to 500 chars per email to save tokens
gmail_send tool
- Parameters:
to(string),subject(string),body(string),replyToId(optional string) - Sends an email (or reply if replyToId provided)
- Returns:
{ success: true, messageId: string }
Step 4: Register Tools
-
Create tool description files:
prompts/tools/tool-descriptions/gmail_read.toonprompts/tools/tool-descriptions/gmail_send.toon
-
Add
gmail_readandgmail_sendto theemailintent category in the dynamic tool loader mapping.
Step 5: Test
- Test
gmail_readwith query"is:inbox"limited to 1 result. - Ask the user to confirm they can see the email subject.
- Optionally test
gmail_sendby sending a test email to the user's own address.
Step 6: Confirm
Report success and remind the user:
- "You can now ask me to read or send emails. Try: 'Check my inbox' or 'Send an email to [address] about [topic]'"
- Gmail tools are automatically selected when the intent classifier detects email-related requests.
- Refresh tokens are stored securely in the vault and auto-refreshed.