[2ff88f42] Implement Webhook Noise Reduction: Filter irrelevant events (Sale, Project) and minor field changes
This commit is contained in:
@@ -24,6 +24,35 @@ def process_job(job, so_client: SuperOfficeClient):
|
||||
logger.info(f"Processing Job {job['id']} ({job['event_type']})")
|
||||
payload = job['payload']
|
||||
event_low = job['event_type'].lower()
|
||||
|
||||
# 0. Fast-Fail on Irrelevant Events (Noise Reduction)
|
||||
if any(x in event_low for x in ["sale.", "project.", "appointment.", "document.", "selection."]):
|
||||
logger.info(f"Skipping irrelevant event type: {job['event_type']}")
|
||||
return "SUCCESS"
|
||||
|
||||
# 0b. Fast-Fail on Irrelevant Field Changes
|
||||
# Only if 'Changes' list is provided by Webhook
|
||||
changes = [c.lower() for c in payload.get("Changes", [])]
|
||||
if changes:
|
||||
# Define what we care about
|
||||
relevant_contact = ["name", "department", "urladdress", "number1", "number2", "country", "business"]
|
||||
relevant_person = ["firstname", "lastname", "jobtitle", "position", "mrmrs"]
|
||||
|
||||
is_relevant = False
|
||||
|
||||
if "contact" in event_low:
|
||||
if any(f in changes for f in relevant_contact):
|
||||
is_relevant = True
|
||||
elif "urls" in changes: # Website might be in Urls collection
|
||||
is_relevant = True
|
||||
|
||||
if "person" in event_low:
|
||||
if any(f in changes for f in relevant_person):
|
||||
is_relevant = True
|
||||
|
||||
if not is_relevant:
|
||||
logger.info(f"Skipping irrelevant changes: {changes}")
|
||||
return "SUCCESS"
|
||||
|
||||
# 1. Extract IDs from Webhook Payload
|
||||
person_id = None
|
||||
|
||||
Reference in New Issue
Block a user