cleanup
This commit is contained in:
124
bitbylaw/steps/vmh/webhook/beteiligte_create_api_step.md
Normal file
124
bitbylaw/steps/vmh/webhook/beteiligte_create_api_step.md
Normal file
@@ -0,0 +1,124 @@
|
||||
---
|
||||
type: step
|
||||
category: api
|
||||
name: VMH Webhook Beteiligte Create
|
||||
version: 1.0.0
|
||||
status: active
|
||||
tags: [webhook, espocrm, vmh, beteiligte, create]
|
||||
dependencies:
|
||||
- redis
|
||||
emits: [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
|
||||
```python
|
||||
{
|
||||
'type': 'api',
|
||||
'name': 'VMH Webhook Beteiligte Create',
|
||||
'path': '/vmh/webhook/beteiligte/create',
|
||||
'method': 'POST',
|
||||
'emits': ['vmh.beteiligte.create'],
|
||||
'flows': ['vmh']
|
||||
}
|
||||
```
|
||||
|
||||
## Input
|
||||
```bash
|
||||
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
|
||||
```json
|
||||
{
|
||||
"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**:
|
||||
```python
|
||||
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:
|
||||
```python
|
||||
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
|
||||
```bash
|
||||
# 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
|
||||
```
|
||||
|
||||
## Related Steps
|
||||
- [beteiligte_update_api_step.md](beteiligte_update_api_step.md) - Update webhooks
|
||||
- [beteiligte_delete_api_step.md](beteiligte_delete_api_step.md) - Delete webhooks
|
||||
- [beteiligte_sync_event_step.md](../beteiligte_sync_event_step.md) - Consumes events
|
||||
Reference in New Issue
Block a user