feat(webhooks): Implement Akte webhooks for create, delete, and update operations
This commit is contained in:
38
src/steps/crm/akte/webhooks/akte_delete_api_step.py
Normal file
38
src/steps/crm/akte/webhooks/akte_delete_api_step.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""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)})
|
||||
Reference in New Issue
Block a user