OpenClawSkills
GitHub
Automation • 5分で読める

Gmail Pub/Sub

gogcli 経由で Gmail Pub/Sub を OpenClaw の Webhook に配信します。

目標:Gmail ウォッチ → Pub/Sub プッシュ → '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'gog gmail watch serve'</code>' → OpenClaw webhook。

Tutorial.step

Prerequisites

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'gcloud'</code>' がインストールされ、ログイン済み('<a href="https://docs.cloud.google.com/sdk/docs/install-sdk" className="text-emerald-400 hover:text-emerald-300 transition-colors">'インストールガイド'</a>')。

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'gog'</code>' (gogcli) が Gmail アカウント用にインストールされ、認証済み('<a href="https://gogcli.sh/" className="text-emerald-400 hover:text-emerald-300 transition-colors">'gogcli.sh'</a>')。

- OpenClaw フックが有効('<a href="/automation/webhook" className="text-emerald-400 hover:text-emerald-300 transition-colors">'Webhooks'</a>' を参照)。

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'tailscale'</code>' がログイン済み('<a href="https://tailscale.com/" className="text-emerald-400 hover:text-emerald-300 transition-colors">'tailscale.com'</a>')。サポートされる設定では Tailscale Funnel をパブリック HTTPS エンドポイントとして使用します。

他のトンネルサービスも動作しますが、DIY/非サポートであり、手動配線が必要です。

現在、Tailscale をサポートしています。

フック設定の例(Gmail プリセットマッピングを有効化):

Json5
{
  hooks: {
    enabled: true,
    token: "OPENCLAW_HOOK_TOKEN",
    path: "/hooks",
    presets: ["gmail"],
  },
}

Gmail 要約をチャットに配信するには、マッピングを使用してプリセットを上書きします

'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'deliver'</code>' + オプション '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'channel'</code>'/'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'to'</code>' を設定:

Json5
{
  hooks: {
    enabled: true,
    token: "OPENCLAW_HOOK_TOKEN",
    presets: ["gmail"],
    mappings: [
      {
        match: { path: "gmail" },
        action: "agent",
        wakeMode: "now",
        name: "Gmail",
        sessionKey: "hook:gmail:{{messages[0].id}}",
        messageTemplate: "New email from {{messages[0].from}}
Subject: {{messages[0].subject}}
{{messages[0].snippet}}
{{messages[0].body}}",
        model: "openai/gpt-5.2-mini",
        deliver: true,
        channel: "last",
        // to: "+15551234567"
      },
    ],
  },
}

固定チャネルが必要な場合は、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'channel'</code>' + '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'to'</code>' を設定します。それ以外の場合 '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'channel: &quot;last&quot;'</code>'

は最後の配信ルートを使用します(WhatsApp にフォールバック)。

Gmail により安価なモデルを実行させるには、マッピングで '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'model'</code>' を設定します

('<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'provider/model'</code>' またはエイリアス)。'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'agents.defaults.models'</code>' を強制する場合は、そこに含めます。

Gmail フック専用にデフォルトのモデルと思考レベルを設定するには、

設定に '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.gmail.model'</code>' / '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.gmail.thinking'</code>' を追加します:

Json5
{
  hooks: {
    gmail: {
      model: "openrouter/meta-llama/llama-3.3-70b-instruct:free",
      thinking: "off",
    },
  },
}

Notes:

- マッピング内のフックごとの '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'model'</code>'/'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'thinking'</code>' はこれらのデフォルトを上書きします。

- フォールバック順序:'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.gmail.model'</code>' → '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'agents.defaults.model.fallbacks'</code>' → プライマリ(認証/レート制限/タイムアウト)。

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'agents.defaults.models'</code>' が設定されている場合、Gmail モデルは許可リストにある必要があります。

- デフォルトでは、Gmail フックコンテンツは外部コンテンツセーフティバウンダリでラップされます。

無効にするには(危険)、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.gmail.allowUnsafeExternalContent: true'</code>' を設定します。

ペイロード処理をさらにカスタマイズするには、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.mappings'</code>' または JS/TS 変換モジュールを追加します

'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.transformsDir'</code>' の下('<a href="/automation/webhook" className="text-emerald-400 hover:text-emerald-300 transition-colors">'Webhooks'</a>' を参照)。

Tutorial.step

ウィザード(推奨)

OpenClaw アシスタントを使用してすべてを接続します(macOS で brew 経由で deps をインストール):

Bash
openclaw webhooks gmail setup   --account [email protected]

デフォルト:

- Tailscale Funnel をパブリックプッシュエンドポイントとして使用します。

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'openclaw webhooks gmail run'</code>' 用の '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'openclaw webhooks gmail run'</code>' 設定を書き込みます。

- Gmail フックプリセットを有効化('<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.presets: [&quot;gmail&quot;]'</code>')。

パスの注意:'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'tailscale.mode'</code>' が有効な場合、OpenClaw は自動的に

'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.gmail.serve.path'</code>' を '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'/'</code>' に設定し、パブリックパスを

'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.gmail.tailscale.path'</code>'(デフォルト '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'/gmail-pubsub'</code>')に保持します。これは Tailscale が

プロキシの前に set-path プレフィックスを削除するためです。

バックエンドがプレフィックスパスを受信する必要がある場合は、

'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.gmail.tailscale.target'</code>' (または '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'--tailscale-target'</code>')を完全な URL に設定します。例:

'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'http://127.0.0.1:8788/gmail-pubsub'</code>' で '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.gmail.serve.path'</code>' と一致させます。

Want custom endpoint? Use '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'--push-endpoint &lt;url&gt;'</code>' or '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'--tailscale off'</code>'.

プラットフォームの注意:macOS では、ウィザードが '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'gcloud'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'gogcli'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'tailscale'</code>' をインストールします

homebrew 経由で;Linux では最初に手動でインストールします。

ゲートウェイ自動起動(推奨):

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.enabled=true'</code>' と '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.gmail.account'</code>' が設定されている場合、ゲートウェイは

'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'gog gmail watch serve'</code>' を起動し、ウォッチを自動更新します。

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'OPENCLAW_SKIP_GMAIL_WATCHER=1'</code>' を設定してオプトアウト(自分でデーモンを実行する場合に便利)。

- 手動デーモンを同時に実行しないでください。そうしないと、

'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'listen tcp 127.0.0.1:8788: bind: address already in use'</code>' が発生します。

手動デーモン('<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'gog gmail watch serve'</code>' 起動 + 自動更新):

Bash
openclaw webhooks gmail run
Tutorial.step

ワンタイムセットアップ

1. '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'gog'</code>' が使用する OAuth クライアントを所有する GCP プロジェクトを選択します。

Bash
gcloud auth login
gcloud config set project <project-id>

注意:Gmail ウォッチは Pub/Sub トピックが OAuth クライアントと同じプロジェクトにある必要があります。

2. API を有効化:

Bash
gcloud services enable gmail.googleapis.com pubsub.googleapis.com

3. トピックを作成:

Bash
gcloud pubsub topics create gog-gmail-watch

4. Gmail プッシュの公開を許可:

Bash
gcloud pubsub topics add-iam-policy-binding gog-gmail-watch   --member=serviceAccount:[email protected]   --role=roles/pubsub.publisher
Tutorial.step

ウォッチを開始

Bash
gog gmail watch start   --account [email protected]   --label INBOX   --topic projects/<project-id>/topics/gog-gmail-watch

出力から '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'history_id'</code>' を保存します(デバッグ用)。

Tutorial.step

プッシュハンドラーを実行

ローカルの例(共有トークン認証):

Bash
gog gmail watch serve   --account [email protected]   --bind 127.0.0.1   --port 8788   --path /gmail-pubsub   --token <shared>   --hook-url http://127.0.0.1:18789/hooks/gmail   --hook-token OPENCLAW_HOOK_TOKEN   --include-body   --max-bytes 20000

Notes:

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'--token'</code>' はプッシュエンドポイントを保護します('<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'x-gog-token'</code>' または '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'?token='</code>')。

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'--hook-url'</code>' は OpenClaw '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'/hooks/gmail'</code>' を指します(マッピング;分離実行 + メインへの要約)。

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'--include-body'</code>' と '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'--max-bytes'</code>' は OpenClaw に送信される本文スニペットを制御します。

推奨:'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'openclaw webhooks gmail run'</code>' は同じフローをラップし、ウォッチを自動更新します。

Tutorial.step

ハンドラーを公開(高度、非サポート)

Tailscale 以外のトンネルが必要な場合は、手動で配線し、プッシュでパブリック URL を使用します

サブスクリプション(非サポート、ガードレールなし):

Bash
cloudflared tunnel --url http://127.0.0.1:8788 --no-autoupdate

生成された URL をプッシュエンドポイントとして使用します:

Bash
gcloud pubsub subscriptions create gog-gmail-watch-push   --topic gog-gmail-watch   --push-endpoint "https://<public-url>/gmail-pubsub?token=<shared>"

本番:安定した HTTPS エンドポイントを使用し、Pub/Sub OIDC JWT を設定してから実行します:

Bash
gog gmail watch serve --verify-oidc --oidc-email <svc@...>
Tutorial.step

テスト

ウォッチしている受信トレイにメッセージを送信します:

Bash
gog gmail send   --account [email protected]   --to [email protected]   --subject "watch test"   --body "ping"

ウォッチのステータスと履歴を確認します:

Bash
gog gmail watch status --account [email protected]
gog gmail history --account [email protected] --since <historyId>
Tutorial.step

トラブルシューティング

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'Invalid topicName'</code>':プロジェクトの不一致(トピックが OAuth クライアントプロジェクトにありません)。

- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'User not authorized'</code>':トピックに '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'roles/pubsub.publisher'</code>' がありません。

- 空のメッセージ:Gmail プッシュは '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'historyId'</code>' のみを提供します。'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'gog gmail history'</code>' 経由で取得します。

Tutorial.step

クリーンアップ

Bash
gog gmail watch stop --account [email protected]
gcloud pubsub subscriptions delete gog-gmail-watch-push
gcloud pubsub topics delete gog-gmail-watch