[31188f42] Feat: Filterlogik für 'person.changed' Webhooks implementiert.
Nur relevante Änderungen (Jobtitel, Position, UDFs) lösen eine KI-Verarbeitung aus. Irrelevante Änderungen (Telefon, etc.) werden ignoriert, um Loops und unnötige Last zu vermeiden.
This commit is contained in:
@@ -52,6 +52,47 @@ def process_job(job, so_client: SuperOfficeClient):
|
|||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# 0b. Noise Reduction: Filter irrelevant field changes
|
||||||
|
# Only re-process if core data (Name, Website) or UDFs (Vertical) changed.
|
||||||
|
if job['event_type'] == 'contact.changed':
|
||||||
|
changes = payload.get('Changes', [])
|
||||||
|
# Normalize to lower case for comparison
|
||||||
|
changes_lower = [str(c).lower() for c in changes]
|
||||||
|
|
||||||
|
# Fields that trigger a re-analysis
|
||||||
|
relevant_fields = [
|
||||||
|
'name', # Company Name change -> Full Re-Scan
|
||||||
|
'urladdress', # Website change -> Full Re-Scan
|
||||||
|
'urls', # Website array change
|
||||||
|
'orgnr', # VAT/Register ID change
|
||||||
|
'userdef_id', # UDFs (Verticals, etc.) changed
|
||||||
|
'country_id' # Country change
|
||||||
|
]
|
||||||
|
|
||||||
|
# Check if ANY relevant field is in the changes list
|
||||||
|
is_relevant = any(field in changes_lower for field in relevant_fields)
|
||||||
|
|
||||||
|
if not is_relevant:
|
||||||
|
logger.info(f"⏭️ Skipping 'contact.changed': No relevant fields changed. (Changes: {changes})")
|
||||||
|
return "SUCCESS"
|
||||||
|
|
||||||
|
if job['event_type'] == 'person.changed':
|
||||||
|
changes = payload.get('Changes', [])
|
||||||
|
changes_lower = [str(c).lower() for c in changes]
|
||||||
|
|
||||||
|
relevant_person_fields = [
|
||||||
|
'jobtitle', # Job Title change
|
||||||
|
'title', # Alternative title field
|
||||||
|
'position_id', # Standard Position/Role dropdown
|
||||||
|
'userdef_id' # UDFs (MA Status, Campaign, etc.)
|
||||||
|
]
|
||||||
|
|
||||||
|
is_relevant = any(field in changes_lower for field in relevant_person_fields)
|
||||||
|
|
||||||
|
if not is_relevant:
|
||||||
|
logger.info(f"⏭️ Skipping 'person.changed': No relevant fields changed. (Changes: {changes})")
|
||||||
|
return "SUCCESS"
|
||||||
|
|
||||||
# 1. Extract IDs Early
|
# 1. Extract IDs Early
|
||||||
person_id = None
|
person_id = None
|
||||||
contact_id = None
|
contact_id = None
|
||||||
|
|||||||
Reference in New Issue
Block a user