Gmail Pub/Sub -> OpenClaw¶
Layunin: Gmail watch -> Pub/Sub push -> gog gmail watch serve -> OpenClaw webhook.
Mga Kinakailangan¶
gcloudnaka-install at naka-log in (install guide).gog(gogcli) naka-install at may awtorisasyon para sa Gmail account (gogcli.sh).- Naka-enable ang OpenClaw hooks (tingnan ang Webhooks).
tailscalena naka-log in (tailscale.com). Ang sinusuportahang setup ay gumagamit ng Tailscale Funnel para sa pampublikong HTTPS endpoint. Maaaring gumana ang ibang tunnel services, ngunit DIY/hindi suportado at nangangailangan ng manu-manong pag-configure. Right now, Tailscale is what we support.
Halimbawang hook config (i-enable ang Gmail preset mapping):
{
hooks: {
enabled: true,
token: "OPENCLAW_HOOK_TOKEN",
path: "/hooks",
presets: ["gmail"],
},
}
Para maihatid ang Gmail summary sa isang chat surface, i-override ang preset gamit ang mapping
na nagse-set ng deliver + opsyonal na channel/to:
{
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}}\nSubject: {{messages[0].subject}}\n{{messages[0].snippet}}\n{{messages[0].body}}",
model: "openai/gpt-5.2-mini",
deliver: true,
channel: "last",
// to: "+15551234567"
},
],
},
}
Kung gusto mo ng nakapirming channel, itakda ang channel + to. Kung hindi, channel: "last"
uses the last delivery route (falls back to WhatsApp).
Upang pilitin ang paggamit ng mas murang model para sa mga Gmail run, itakda ang model sa mapping
(provider/model or alias). If you enforce agents.defaults.models, include it there.
Para magtakda ng default na model at thinking level na partikular para sa Gmail hooks, idagdag
ang hooks.gmail.model / hooks.gmail.thinking sa iyong config:
{
hooks: {
gmail: {
model: "openrouter/meta-llama/llama-3.3-70b-instruct:free",
thinking: "off",
},
},
}
Mga tala:
- Ang per-hook
model/thinkingsa mapping ay nag-o-override pa rin sa mga default na ito. - Fallback order:
hooks.gmail.model→agents.defaults.model.fallbacks→ primary (auth/rate-limit/timeouts). - Kung naka-set ang
agents.defaults.models, dapat nasa allowlist ang Gmail model. - Ang nilalaman ng Gmail hook ay nakabalot sa external-content safety boundaries bilang default.
Upang i-disable (mapanganib), itakda ang
hooks.gmail.allowUnsafeExternalContent: true.
Para mas i-customize pa ang payload handling, idagdag ang hooks.mappings o isang JS/TS transform module
sa ilalim ng hooks.transformsDir (tingnan ang Webhooks).
Wizard (inirerekomenda)¶
Gamitin ang OpenClaw helper para i-wire ang lahat (nag-i-install ng deps sa macOS gamit ang brew):
openclaw webhooks gmail setup \
--account openclaw@gmail.com
Mga default:
- Gumagamit ng Tailscale Funnel para sa public push endpoint.
- Nagsusulat ng
hooks.gmailconfig para saopenclaw webhooks gmail run. - Ina-enable ang Gmail hook preset (
hooks.presets: ["gmail"]).
Path note: when tailscale.mode is enabled, OpenClaw automatically sets
hooks.gmail.serve.path to / and keeps the public path at
hooks.gmail.tailscale.path (default /gmail-pubsub) because Tailscale
strips the set-path prefix before proxying.
If you need the backend to receive the prefixed path, set
hooks.gmail.tailscale.target (or --tailscale-target) to a full URL like
http://127.0.0.1:8788/gmail-pubsub and match hooks.gmail.serve.path.
Want a custom endpoint? Use --push-endpoint <url> or --tailscale off.
Platform note: sa macOS ini-install ng wizard ang gcloud, gogcli, at tailscale
sa pamamagitan ng Homebrew; sa Linux, i-install muna ang mga ito nang mano-mano.
Gateway auto-start (inirerekomenda):
- Kapag naka-set ang
hooks.enabled=trueathooks.gmail.account, sinisimulan ng Gateway anggog gmail watch servesa boot at awtomatikong nagre-renew ng watch. - I-set ang
OPENCLAW_SKIP_GMAIL_WATCHER=1para mag-opt out (kapaki-pakinabang kung ikaw mismo ang nagpapatakbo ng daemon). - Huwag patakbuhin ang manual daemon nang sabay, o tatama ka sa
listen tcp 127.0.0.1:8788: bind: address already in use.
Manual daemon (sinisimulan ang gog gmail watch serve + auto-renew):
openclaw webhooks gmail run
One-time setup¶
- Piliin ang GCP project na may-ari ng OAuth client na ginagamit ng
gog.
gcloud auth login
gcloud config set project <project-id>
Tala: Kailangan ng Gmail watch na ang Pub/Sub topic ay nasa parehong project ng OAuth client.
- I-enable ang mga API:
gcloud services enable gmail.googleapis.com pubsub.googleapis.com
- Gumawa ng topic:
gcloud pubsub topics create gog-gmail-watch
- Payagan ang Gmail push na mag-publish:
gcloud pubsub topics add-iam-policy-binding gog-gmail-watch \
--member=serviceAccount:gmail-api-push@system.gserviceaccount.com \
--role=roles/pubsub.publisher
Simulan ang watch¶
gog gmail watch start \
--account openclaw@gmail.com \
--label INBOX \
--topic projects/<project-id>/topics/gog-gmail-watch
I-save ang history_id mula sa output (para sa debugging).
Patakbuhin ang push handler¶
Local na halimbawa (shared token auth):
gog gmail watch serve \
--account openclaw@gmail.com \
--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
Mga tala:
- Pinoprotektahan ng
--tokenang push endpoint (x-gog-tokeno?token=). - Tumuturo ang
--hook-urlsa OpenClaw/hooks/gmail(mapped; isolated run + summary sa main). - Kinokontrol ng
--include-bodyat--max-bytesang body snippet na ipinapadala sa OpenClaw.
Inirerekomenda: binabalot ng openclaw webhooks gmail run ang parehong daloy at awtomatikong nire-renew ang watch.
I-expose ang handler (advanced, unsupported)¶
Kung kailangan mo ng non-Tailscale tunnel, i-wire ito nang mano-mano at gamitin ang public URL sa push subscription (unsupported, walang guardrails):
cloudflared tunnel --url http://127.0.0.1:8788 --no-autoupdate
Gamitin ang nabuo na URL bilang push endpoint:
gcloud pubsub subscriptions create gog-gmail-watch-push \
--topic gog-gmail-watch \
--push-endpoint "https://<public-url>/gmail-pubsub?token=<shared>"
Production: gumamit ng stable na HTTPS endpoint at i-configure ang Pub/Sub OIDC JWT, pagkatapos ay patakbuhin:
gog gmail watch serve --verify-oidc --oidc-email <svc@...>
Test¶
Magpadala ng mensahe sa mino-monitor na inbox:
gog gmail send \
--account openclaw@gmail.com \
--to openclaw@gmail.com \
--subject "watch test" \
--body "ping"
Suriin ang watch state at history:
gog gmail watch status --account openclaw@gmail.com
gog gmail history --account openclaw@gmail.com --since <historyId>
Pag-troubleshoot¶
Invalid topicName: hindi tugmang project (ang topic ay wala sa OAuth client project).User not authorized: nawawala angroles/pubsub.publishersa topic.- Walang laman na mga mensahe: nagbibigay lang ang Gmail push ng
historyId; kunin sa pamamagitan nggog gmail history.
Cleanup¶
gog gmail watch stop --account openclaw@gmail.com
gcloud pubsub subscriptions delete gog-gmail-watch-push
gcloud pubsub topics delete gog-gmail-watch