Webhook¶
Webhook handling utilities for Arshai.
Classes¶
- class arshai.web.webhook.WebhookConfig(secret=None, signature_header='X-Signature', signature_prefix='', hash_algorithm='sha256', max_body_size=10485760)[source]¶
Bases:
objectConfiguration for webhook handler.
- __init__(secret=None, signature_header='X-Signature', signature_prefix='', hash_algorithm='sha256', max_body_size=10485760)¶
- class arshai.web.webhook.WebhookHandler(config=None)[source]¶
Bases:
objectGeneric webhook handler with signature verification.
This is an OPTIONAL utility for handling webhooks. Existing Arshai applications are not affected by this addition.
Example
# Create handler with secret handler = WebhookHandler(WebhookConfig(secret=”my-secret”))
# In FastAPI/Flask route @app.post(“/webhook”) async def handle_webhook(request: Request):
# Verify and process data = await handler.process_request(request)
# Use with Arshai workflow workflow = MyWorkflow() result = await workflow.execute(IWorkflowState(data=data)) return result
- Extending for specific platforms (in your application code):
- class GitHubWebhookHandler(WebhookHandler):
- def __init__(self, secret: str):
- super().__init__(WebhookConfig(
secret=secret, signature_header=”X-Hub-Signature-256”, signature_prefix=”sha256=”, hash_algorithm=”sha256”
))
- def is_pull_request_event(self, data: Dict[str, Any]) -> bool:
return “pull_request” in data
- __init__(config=None)[source]¶
Initialize webhook handler.
- Parameters:
config (
Optional[WebhookConfig]) – Optional configuration
- async process_request(request)[source]¶
Process incoming webhook request.
- Parameters:
request (
Any) – HTTP request object (FastAPI Request, Flask request, etc.)- Return type:
- Returns:
Parsed webhook data
- Raises:
WebhookValidationError – If validation fails