クイックスタート
このガイドでは、シンプルなWebhook転送エージェントでOpenPR-Webhookをセットアップし、シミュレートされたイベントでテストする方法を説明します。
ステップ1: 設定を作成
config.tomlという名前のファイルを作成:
toml
[server]
listen = "0.0.0.0:9000"
[security]
webhook_secrets = ["my-test-secret"]
[[agents]]
id = "echo-agent"
name = "Echo Agent"
agent_type = "webhook"
[agents.webhook]
url = "https://httpbin.org/post"この設定は:
- ポート9000でリッスン
- シークレット
my-test-secretを使用したHMAC-SHA256署名を要求 - テスト用にhttpbin.orgにボットイベントをルーティング
ステップ2: サービスを起動
bash
./target/release/openpr-webhook config.toml以下のメッセージが表示されるはずです:
INFO openpr_webhook: Loaded 1 agent(s)
INFO openpr_webhook: tunnel subsystem disabled (feature flag or safe mode)
INFO openpr_webhook: openpr-webhook listening on 0.0.0.0:9000ステップ3: テストイベントを送信
テストペイロードのHMAC-SHA256署名を生成して送信:
bash
# The test payload
PAYLOAD='{"event":"issue.updated","bot_context":{"is_bot_task":true,"bot_name":"echo-agent","bot_agent_type":"webhook"},"data":{"issue":{"id":"42","key":"PROJ-42","title":"Fix login bug"}},"actor":{"name":"alice"},"project":{"name":"backend"}}'
# Compute HMAC-SHA256 signature
SIG=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "my-test-secret" | awk '{print $2}')
# Send the webhook
curl -X POST http://localhost:9000/webhook \
-H "Content-Type: application/json" \
-H "X-Webhook-Signature: sha256=$SIG" \
-d "$PAYLOAD"期待されるレスポンス:
json
{
"status": "dispatched",
"agent": "echo-agent",
"result": "webhook: 200 OK"
}ステップ4: フィルタリングをテスト
bot_context.is_bot_task = trueのないイベントはサイレントに無視されます:
bash
PAYLOAD='{"event":"issue.created","data":{"issue":{"id":"1"}}}'
SIG=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "my-test-secret" | awk '{print $2}')
curl -X POST http://localhost:9000/webhook \
-H "Content-Type: application/json" \
-H "X-Webhook-Signature: sha256=$SIG" \
-d "$PAYLOAD"レスポンス:
json
{
"status": "ignored",
"reason": "not_bot_task"
}ステップ5: 署名拒否をテスト
無効な署名はHTTP 401を返します:
bash
curl -X POST http://localhost:9000/webhook \
-H "Content-Type: application/json" \
-H "X-Webhook-Signature: sha256=invalid" \
-d '{"event":"test"}'レスポンス:401 Unauthorized
エージェントマッチングの理解
is_bot_task = trueでWebhookイベントが届くと、サービスは以下のロジックでエージェントをマッチングします:
- 名前によるマッチ --
bot_context.bot_nameがエージェントのidまたはnameと一致する場合(大文字小文字を区別しない) - タイプによるフォールバック -- 名前マッチがなければ、
agent_typeがbot_context.bot_agent_typeと一致する最初のエージェントを使用
エージェントがマッチしない場合、レスポンスには"status": "no_agent"が含まれます。
次のステップ
- エージェントタイプ -- 5つのエージェントタイプすべてについて学ぶ
- エグゼキュータリファレンス -- 各エグゼキュータの詳細
- 設定リファレンス -- 完全なTOMLスキーマ