oclaw/runtime/extensions/webhooks/index.py
oliver 4a23b715a2 重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。

Made-with: Cursor
2026-04-25 01:24:23 +08:00

26 lines
1.3 KiB
Python

from __future__ import annotations
from .config import resolve_webhooks_plugin_config
from .http import TaskFlowWebhookTarget, create_taskflow_webhook_request_handler
def register_webhook_routes(api) -> None:
routes = resolve_webhooks_plugin_config(plugin_config=getattr(api, "plugin_config", {}) or {})
if not routes:
return
targets_by_path: dict[str, list[TaskFlowWebhookTarget]] = {}
handler = create_taskflow_webhook_request_handler(cfg=getattr(api, "config", {}) or {}, targets_by_path=targets_by_path)
for route in routes:
task_flow = api.runtime.task_flow.bind_session(session_key=route.session_key)
target = TaskFlowWebhookTarget(
route_id=route.route_id,
path=route.path,
secret_input=route.secret,
secret_config_path=f"plugins.entries.webhooks.routes.{route.route_id}.secret",
default_controller_id=route.controller_id,
task_flow=task_flow,
)
targets_by_path.setdefault(target.path, []).append(target)
api.register_http_route(path=target.path, auth="plugin", match="exact", replace_existing=True, handler=handler)
api.logger.info(f"[webhooks] registered route {route.route_id} on {route.path} for session {route.session_key}")