Webhook
エージェント実行を起動し、分離するための Webhook エントリポイント。
ゲートウェイは外部トリガー用の小さなHTTP Webhookエンドポイントを公開できます。
Enable
{
hooks: {
enabled: true,
token: "shared-secret",
path: "/hooks",
},
}Notes:
- '<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.enabled=true'</code>' が必要です。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.path'</code>' はデフォルトで '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'/hooks'</code>' です。
Authorization
各リクエストにはフックトークンを含める必要があります。推奨ヘッダー:
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'Authorization: Bearer <token>'</code>' (recommended)
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'x-openclaw-token: <token>'</code>'
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'?token=<token>'</code>' (deprecated; logs warning and will be removed in a future major version)
エンドポイント
#
`POST /hooks/wake`
ペイロード:
{ "text": "System line", "mode": "now" }- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'text'</code>' '<strong>'必須'</strong>'(文字列):イベントの説明(例:"新しいメールを受信")。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'mode'</code>' オプション ('<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'now'</code>' | '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'next-heartbeat'</code>'):直ちにハートビートをトリガーするか(デフォルト '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'now'</code>')、次の定期チェックを待つか。
Effects:
- システムイベントを <strong>main</strong> セッションのキューに入れる
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'mode=now'</code>' の場合、直ちにハートビートをトリガーする
#
`POST /hooks/agent`
ペイロード:
{
"message": "Run this",
"name": "Email",
"sessionKey": "hook:email:msg-123",
"wakeMode": "now",
"deliver": true,
"channel": "last",
"to": "+15551234567",
"model": "openai/gpt-5.2-mini",
"thinking": "low",
"timeoutSeconds": 120
}- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'message'</code>' '<strong>'必須'</strong>'(文字列):エージェントが処理するプロンプトまたはメッセージ。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'name'</code>' オプション(文字列):人間が読めるフック名(例:"GitHub")、セッション要約のプレフィックスとして使用されます。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'sessionKey'</code>' optional (string): Key to identify the agent session. Defaults to a random '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hook:<uuid>'</code>'. Using a consistent key allows multi-turn conversations within the hook context.
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'wakeMode'</code>' オプション ('<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'now'</code>' | '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'next-heartbeat'</code>'):直ちにハートビートをトリガーするか(デフォルト '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'now'</code>')、次の定期チェックを待つか。
- '<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">'true'</code>' の場合、エージェントの応答がメッセージングチャネルに送信されます。デフォルトは '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'true'</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">'last'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'whatsapp'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'telegram'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'discord'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'slack'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'mattermost'</code>'(プラグイン)、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'signal'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'imessage'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'msteams'</code>'。デフォルトは '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'last'</code>'。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'to'</code>' オプション(文字列):チャネルの受信者識別子(例:WhatsApp/Signalの電話番号、TelegramのチャットID、Discord/Slack/Mattermost(プラグイン)のチャネルID、MS Teamsの会話ID)。デフォルトはメインセッションの最後の受信者。
- '<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">'anthropic/claude-3-5-sonnet'</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">'low'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'medium'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'high'</code>')。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'timeoutSeconds'</code>' オプション(数値):エージェント実行の最大時間(秒単位)。
Effects:
- <strong>分離された</strong>エージェントターンを実行(独自のセッションキー)
- 常に要約を <strong>main</strong> セッションに公開
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'wakeMode=now'</code>' の場合、直ちにハートビートをトリガーする
#
`POST /hooks/<name>` (mapped)
カスタムフック名は '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.mappings'</code>' を介して解決されます(設定を参照)。マッピングは
オプションのテンプレートを使用するか、任意のペイロードを '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'wake'</code>' または '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'agent'</code>' アクションに変換できます
コード変換を介して。
マッピングオプション(概要):
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.presets: ["gmail"]'</code>' は組み込みのGmailマッピングを有効にします。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.mappings'</code>' はconfig.jsonで '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'match'</code>'、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'action'</code>'、テンプレートを定義できます。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'hooks.transformsDir'</code>' + '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'transform.module'</code>' はカスタムロジックのJS/TSモジュールをロードします。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'match.source'</code>' を使用して汎用取り込みエンドポイント(ペイロード駆動ルーティング)を保持します。
- TS変換にはTSローダー(例:'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'bun'</code>' または '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'tsx'</code>')が必要か、実行時に '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'.js'</code>' をプリコンパイルします。
- マッピングに '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'deliver: true'</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>' を設定して、返信をチャットインターフェースにルーティングします
('<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">'last'</code>' で、WhatsAppにフォールバックします)。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'allowUnsafeExternalContent: true'</code>' はそのフックの外部コンテンツ安全ラッパーを無効にします
(危険;信頼できる内部ソースのみ)。
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'openclaw webhooks gmail setup'</code>' は '<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ウォッチフローについては、'<a href="/automation/gmail-pubsub" className="text-emerald-400 hover:text-emerald-300 transition-colors">'Gmail Pub/Sub'</a>' を参照してください。
Responses
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'200'</code>' は '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'/hooks/wake'</code>' 用
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'202'</code>' は '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'/hooks/agent'</code>' 用(非同期実行開始)
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'401'</code>' authorization failed
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'400'</code>' 無効なペイロード
- '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'413'</code>' ペイロードが大きすぎます
Examples
curl -X POST http://127.0.0.1:18789/hooks/wake -H 'Authorization: Bearer SECRET' -H 'Content-Type: application/json' -d '{"text":"New email received","mode":"now"}'curl -X POST http://127.0.0.1:18789/hooks/agent -H 'x-openclaw-token: SECRET' -H 'Content-Type: application/json' -d '{"message":"Summarize inbox","name":"Email","wakeMode":"next-heartbeat"}'#
別のモデルを使用する
エージェントペイロード(またはマッピング)に '<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'model'</code>' を追加して、その実行のモデルをオーバーライドします:
curl -X POST http://127.0.0.1:18789/hooks/agent -H 'x-openclaw-token: SECRET' -H 'Content-Type: application/json' -d '{"message":"Summarize inbox","name":"Email","model":"openai/gpt-5.2-mini"}''<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'agents.defaults.models'</code>' を強制する場合、オーバーライドモデルが含まれていることを確認してください。
curl -X POST http://127.0.0.1:18789/hooks/gmail -H 'Authorization: Bearer SECRET' -H 'Content-Type: application/json' -d '{"source":"gmail","messages":[{"from":"Ada","subject":"Hello","snippet":"Hi"}]}'セキュリティ
- フックエンドポイントをループバック、Tailscale、または信頼できるリバースプロキシの背後に配置します。
- 専用のフックトークンを使用します;ゲートウェイ認証トークンを再利用しないでください。
- Webhookログに機密の生ペイロードを含めることを避けます。
- デフォルトでは、フックペイロードは信頼できないと見なされ、安全境界でラップされます。
特定のフックでこれを無効にする必要がある場合、'<code className="bg-white/10 px-1.5 py-0.5 rounded text-emerald-300 text-sm">'allowUnsafeExternalContent: true'</code>' を設定します
そのフックのマッピングで(危険)。