Files
motia/bitbylaw/steps/vmh/webhook/beteiligte_create_api_step.md
2026-02-07 09:23:49 +00:00

2.9 KiB

type, category, name, version, status, tags, dependencies, emits
type category name version status tags dependencies emits
step api VMH Webhook Beteiligte Create 1.0.0 active
webhook
espocrm
vmh
beteiligte
create
redis
vmh.beteiligte.create

VMH Webhook Beteiligte Create Step

Zweck

Empfängt Create-Webhooks von EspoCRM für neue Beteiligte-Entitäten. Dedupliziert via Redis und emittiert Events für asynchrone Verarbeitung.

Config

{
    'type': 'api',
    'name': 'VMH Webhook Beteiligte Create',
    'path': '/vmh/webhook/beteiligte/create',
    'method': 'POST',
    'emits': ['vmh.beteiligte.create'],
    'flows': ['vmh']
}

Input

POST /vmh/webhook/beteiligte/create
Content-Type: application/json

[
  {
    "id": "entity-123",
    "name": "Max Mustermann",
    "createdAt": "2026-02-07T10:00:00Z"
  },
  {
    "id": "entity-456",
    "name": "Maria Schmidt"
  }
]

Format: Array von Entitäten (Batch-Support)

Output

{
  "status": "received",
  "action": "create",
  "new_ids_count": 2,
  "total_ids_in_batch": 2
}

Verhalten

  1. Extract IDs von allen Entitäten im Batch
  2. Redis Deduplication:
    pending_key = 'vmh:beteiligte:create_pending'
    existing_ids = redis.smembers(pending_key)
    new_ids = input_ids - existing_ids
    redis.sadd(pending_key, *new_ids)
    
  3. Emit Events nur für neue IDs:
    for entity_id in new_ids:
        await context.emit({
            'topic': 'vmh.beteiligte.create',
            'data': {
                'entity_id': entity_id,
                'action': 'create',
                'source': 'webhook',
                'timestamp': timestamp
            }
        })
    

Redis Keys

  • vmh:beteiligte:create_pending (SET): IDs in create queue
  • No TTL (permanent until processed)

Deduplication Logic

Problem: EspoCRM kann Webhooks mehrfach senden Solution: Redis SET speichert alle pending IDs

  • Neue IDs → Events emittiert
  • Bereits vorhandene IDs → Skipped

Testing

# Test webhook
curl -X POST "http://localhost:3000/vmh/webhook/beteiligte/create" \
  -H "Content-Type: application/json" \
  -d '[{"id": "test-123", "name": "Test"}]'

# Check Redis
redis-cli -n 1 SMEMBERS vmh:beteiligte:create_pending

# Clear Redis (testing)
redis-cli -n 1 DEL vmh:beteiligte:create_pending

Error Handling

  • Invalid JSON: 400 error
  • Redis unavailable: Loggen, aber nicht crashen (kann zu Duplikaten führen)
  • Event emission error: Loggen und fortfahren

Monitoring

[INFO] VMH Webhook Beteiligte Create empfangen
[INFO] Create Entity ID gefunden: entity-123
[INFO] 2 neue IDs zur Create-Sync-Queue hinzugefügt
[INFO] Create-Event emittiert für ID: entity-123