Chuyển tới nội dung chính

Webhook Notification Handler Agent

The Webhook Notification Handler Agent delivers notifications to external systems via HTTP webhooks.

📋 Overview

PropertyValue
Modulesrc.agents.notification.webhook_notification_handler_agent
ClassWebhookNotificationHandlerAgent
AuthorUIP Team
Version1.0.0

🎯 Purpose

  • Deliver notifications to external HTTP endpoints
  • Support various authentication methods
  • Handle retries for failed deliveries
  • Track delivery status and metrics

🚀 Usage

Register Webhook

from src.agents.notification.webhook_notification_handler_agent import WebhookNotificationHandlerAgent

handler = WebhookNotificationHandlerAgent()

# Register webhook endpoint
webhook = await handler.register_webhook({
"name": "Emergency Services",
"url": "https://emergency.city.gov/api/alerts",
"events": ["accident.high", "accident.critical"],
"auth": {
"type": "bearer",
"token": "${EMERGENCY_API_TOKEN}"
}
})

Send Notification

# Send webhook notification
result = await handler.send(
webhook_id="WH_001",
event="accident.high",
payload={
"incident_id": "ACC_001",
"location": {"lat": 10.8231, "lon": 106.6297},
"severity": "high",
"timestamp": "2025-11-29T10:30:00Z"
}
)

Batch Send

# Send to multiple webhooks
results = await handler.broadcast(
event="congestion.severe",
payload=congestion_data,
webhook_filter={"category": "traffic_ops"}
)

⚙️ Configuration

# config/webhook_config.yaml
webhook_handler:
enabled: true

# Delivery settings
delivery:
timeout_seconds: 30
max_retries: 5
retry_delays: [1, 5, 30, 300, 900] # Exponential backoff

# Security
security:
sign_payloads: true
signing_algorithm: "HMAC-SHA256"
include_timestamp: true

# Registered webhooks
webhooks:
- name: "Emergency Services"
url: "https://emergency.city.gov/api/alerts"
events: ["accident.*"]
auth:
type: "bearer"
token: "${EMERGENCY_TOKEN}"

- name: "Traffic Control"
url: "https://traffic.city.gov/webhooks"
events: ["congestion.*", "accident.*"]
auth:
type: "basic"
username: "${TC_USER}"
password: "${TC_PASS}"

📊 Webhook Events

Event PatternDescriptionPriority
accident.*All accident eventsHigh
accident.criticalCritical accidentsImmediate
congestion.severeSevere congestionHigh
system.healthHealth statusLow

🔐 Authentication Types

TypeDescriptionHeaders
bearerBearer tokenAuthorization: Bearer <token>
basicBasic authAuthorization: Basic <base64>
api_keyAPI key headerX-API-Key: <key>
customCustom headersUser-defined

See the complete agents reference for all available agents.