Webhook
Gateway 閘道器可以對外暴露一個小型的 HTTP Webhook 端點,供外部觸發使用。啟用
- 當
hooks.enabled=true時,需要hooks.token。 hooks.path預設為/hooks。
Auth
Every request must include the hook token. Prefer headers:Authorization: Bearer <token>(建議)x-openclaw-token: <token>- 查詢字串 token 會被拒絕(
?token=...會回傳400)。
端點
POST /hooks/wake
Payload:
text必填(string):事件的描述(例如:「New email received」)。mode選填(now|next-heartbeat):是否立即觸發心跳(預設now),或等待下一次定期檢查。
- 將系統事件加入 main 工作階段的佇列
- 若為
mode=now,則立即觸發心跳
POST /hooks/agent
Payload:
message必填(string):要讓代理程式處理的提示或訊息。name選填(string):Hook 的人類可讀名稱(例如:「GitHub」),用作工作階段摘要中的前綴。agentId為選填(字串):將此 hook 路由至指定 agent。 未知的 ID 會回退至預設 agent。 設定後,hook 會使用解析後 agent 的 workspace 與設定執行。sessionKeyoptional (string): The key used to identify the agent’s session. 預設情況下,此欄位會被拒絕,除非設定hooks.allowRequestSessionKey=true。wakeMode選填(now|next-heartbeat):是否立即觸發心跳(預設now),或等待下一次定期檢查。deliver選填(boolean):若為true,代理程式的回應將送至訊息頻道。預設為true。僅為心跳確認的回應會自動略過。 Defaults totrue. Defaults totrue. Responses that are only heartbeat acknowledgments are automatically skipped.channeloptional (string): The messaging channel for delivery.channel選填(string):投遞用的訊息頻道。其一:last、whatsapp、telegram、discord、slack、mattermost(外掛)、signal、imessage、msteams。預設為last。 Defaults tolast. Defaults tolast.to選填(string):該頻道的收件者識別碼(例如:WhatsApp/Signal 的電話號碼、Telegram 的 chat ID、Discord/Slack/Mattermost(外掛)的 channel ID、MS Teams 的 conversation ID)。預設為主要工作階段中的最後一位收件者。 Defaults to the last recipient in the main session. Defaults to the last recipient in the main session.model選填(string):模型覆寫(例如:anthropic/claude-3-5-sonnet或別名)。若有限制,必須包含於允許的模型清單中。 Must be in the allowed model list if restricted. Must be in the allowed model list if restricted.thinking選填(string):思考層級覆寫(例如:low、medium、high)。timeoutSeconds選填(number):代理程式執行的最長時間(秒)。
- 執行一次 隔離 的代理程式回合(獨立的工作階段鍵)
- Always posts a summary into the main session
- 若為
wakeMode=now,則立即觸發心跳
Session key 政策(重大變更)
/hooks/agent payload 中的 sessionKey 覆寫預設為停用。
- 建議:設定固定的
hooks.defaultSessionKey,並保持停用請求覆寫。 - 選用:僅在必要時允許請求覆寫,並限制前綴。
POST /hooks/<name>(映射)
Custom hook names are resolved via hooks.mappings (see configuration). A mapping can
turn arbitrary payloads into wake or agent actions, with optional templates or
code transforms.
映射選項(摘要):
hooks.presets: ["gmail"]啟用內建的 Gmail 映射。hooks.mappings可讓你在設定中定義match、action與範本。hooks.transformsDir+transform.module載入 JS/TS 模組以實作自訂邏輯。hooks.transformsDir(若已設定)必須位於你的 OpenClaw 設定目錄下的 transforms 根目錄內(通常為~/.openclaw/hooks/transforms)。transform.module必須在實際生效的 transforms 目錄內解析(不接受路徑遍歷/跳脫路徑)。
- 使用
match.source以保留通用的 ingest 端點(以 Payload 驅動路由)。 - TS 轉換在執行時需要 TS 載入器(例如:
bun或tsx),或預先編譯的.js。 - 在映射上設定
deliver: true+channel/to,即可將回覆路由到聊天介面 (channel預設為last,並回退至 WhatsApp)。 agentId會將 hook 路由至指定的 agent;未知的 ID 會回退至預設 agent。hooks.allowedAgentIds會限制可明確指定的agentId路由。 省略此項(或包含*)即可允許任何 agent。 設為[]以拒絕明確指定的agentId路由。hooks.defaultSessionKey會在未提供明確 key 時,設定 hook agent 執行的預設 session。hooks.allowRequestSessionKey控制/hooks/agent的 payload 是否可設定sessionKey(預設:false)。hooks.allowedSessionKeyPrefixes可選擇性限制來自請求 payload 與對應設定中的明確sessionKey值。allowUnsafeExternalContent: true會停用該 Hook 的外部內容安全包裝 (危險;僅適用於受信任的內部來源)。openclaw webhooks gmail setup會為openclaw webhooks gmail run寫入hooks.gmail設定。 完整的 Gmail watch 流程請參見 Gmail Pub/Sub。 See Gmail Pub/Sub for the full Gmail watch flow. See Gmail Pub/Sub for the full Gmail watch flow.
回應
200用於/hooks/wake202用於/hooks/agent(已開始非同步執行)- 驗證失敗時為
401 - 來自同一客戶端在多次驗證失敗後出現
429(請檢查Retry-After) - Payload 無效時為
400 - Payload 過大時為
413
範例
使用不同的模型
在代理程式 Payload(或映射)中加入model,即可覆寫該次執行的模型:
agents.defaults.models,請確保覆寫的模型包含於其中。
安全性
- 將 Hook 端點置於 loopback、tailnet,或受信任的反向代理之後。
- Use a dedicated hook token; do not reuse gateway auth tokens.
- 針對同一客戶端位址的重複驗證失敗會進行速率限制,以減緩暴力破解嘗試。
- 如果使用多 agent 路由,請設定
hooks.allowedAgentIds以限制可明確選擇的agentId。 - 除非需要由呼叫端選擇 session,否則請保持
hooks.allowRequestSessionKey=false。 - 如果啟用請求中的
sessionKey,請限制hooks.allowedSessionKeyPrefixes(例如[“hook:”])。 - 避免在 Webhook 記錄中包含敏感的原始 Payload。
- Hook payloads are treated as untrusted and wrapped with safety boundaries by default.
If you must disable this for a specific hook, set
allowUnsafeExternalContent: truein that hook’s mapping (dangerous).