feat: Enhance AI Knowledge Update webhook handler to validate payload structure and handle empty lists

This commit is contained in:
bsiggel
2026-03-12 22:51:44 +00:00
parent 46c0bbf381
commit 6f7f847939

View File

@@ -31,6 +31,24 @@ async def handler(request: ApiRequest, ctx: FlowContext[Any]) -> ApiResponse:
# Extract payload
payload = request.body
# Handle case where payload is a list (e.g., from array-based webhook)
if isinstance(payload, list):
if not payload:
ctx.logger.error("❌ Empty payload list")
return ApiResponse(
status=400,
body={'success': False, 'error': 'Empty payload'}
)
payload = payload[0] # Take first item
# Ensure payload is a dict
if not isinstance(payload, dict):
ctx.logger.error(f"❌ Invalid payload type: {type(payload)}")
return ApiResponse(
status=400,
body={'success': False, 'error': f'Invalid payload type: {type(payload).__name__}'}
)
# Validate required fields
knowledge_id = payload.get('entity_id') or payload.get('id')
entity_type = payload.get('entity_type', 'CAIKnowledge')