39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
"""Akte Webhook - Delete"""
|
|
import json
|
|
from typing import Any
|
|
from motia import FlowContext, http, ApiRequest, ApiResponse
|
|
|
|
|
|
config = {
|
|
"name": "Akte Webhook - Delete",
|
|
"description": "Empfängt EspoCRM-Delete-Webhooks für CAkten (kein Sync notwendig)",
|
|
"flows": ["akte-sync"],
|
|
"triggers": [http("POST", "/crm/akte/webhook/delete")],
|
|
"enqueues": [],
|
|
}
|
|
|
|
|
|
async def handler(request: ApiRequest, ctx: FlowContext[Any]) -> ApiResponse:
|
|
try:
|
|
payload = request.body or {}
|
|
|
|
entity_ids: set[str] = set()
|
|
if isinstance(payload, list):
|
|
for item in payload:
|
|
if isinstance(item, dict) and 'id' in item:
|
|
entity_ids.add(item['id'])
|
|
elif isinstance(payload, dict) and 'id' in payload:
|
|
entity_ids.add(payload['id'])
|
|
|
|
ctx.logger.info("=" * 60)
|
|
ctx.logger.info("📥 AKTE WEBHOOK: DELETE")
|
|
ctx.logger.info(f" IDs: {entity_ids}")
|
|
ctx.logger.info(" → Kein Sync (Entität gelöscht)")
|
|
ctx.logger.info("=" * 60)
|
|
|
|
return ApiResponse(status_code=200, body={"status": "received", "action": "delete", "ids_count": len(entity_ids)})
|
|
|
|
except Exception as e:
|
|
ctx.logger.error(f"❌ Webhook error: {e}")
|
|
return ApiResponse(status_code=500, body={"error": str(e)})
|