Spaces:
Runtime error
Runtime error
Rename salesforce_dispatcher.py to services/salesforce_dispatcher.py
Browse files- salesforce_dispatcher.py +0 -15
- services/salesforce_dispatcher.py +18 -0
salesforce_dispatcher.py
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
import json
|
3 |
-
|
4 |
-
SALESFORCE_WEBHOOK_URL = "https://your-salesforce-instance/services/web-to-case"
|
5 |
-
|
6 |
-
def send_to_salesforce(payload):
|
7 |
-
alert_type = "Intrusion" if any(d["label"] == "person" for d in payload["detections"]) else "Anomaly"
|
8 |
-
summary = {
|
9 |
-
"Alert_Type__c": alert_type,
|
10 |
-
"ThermalFlag__c": payload["thermal"],
|
11 |
-
"ShadowFlag__c": payload["shadow_issue"],
|
12 |
-
"Confidence_Score__c": max([d["score"] for d in payload["detections"]], default=0)
|
13 |
-
}
|
14 |
-
headers = {"Content-Type": "application/json"}
|
15 |
-
requests.post(SALESFORCE_WEBHOOK_URL, json=summary, headers=headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services/salesforce_dispatcher.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
SALESFORCE_WEBHOOK_URL = "https://your-salesforce-instance/web-to-case"
|
4 |
+
|
5 |
+
def send_to_salesforce(payload):
|
6 |
+
summary = {
|
7 |
+
"Alert_Type__c": "Intrusion" if any(d["label"] == "person" for d in payload["detections"]) else "Fault",
|
8 |
+
"Thermal_Alert__c": payload["thermal"],
|
9 |
+
"Shadow_Alert__c": payload["shadow_issue"],
|
10 |
+
"Confidence__c": max([d["score"] for d in payload["detections"]], default=0)
|
11 |
+
}
|
12 |
+
|
13 |
+
headers = {"Content-Type": "application/json"}
|
14 |
+
try:
|
15 |
+
response = requests.post(SALESFORCE_WEBHOOK_URL, json=summary, headers=headers)
|
16 |
+
print("Salesforce Response:", response.status_code)
|
17 |
+
except Exception as e:
|
18 |
+
print("Error sending to Salesforce:", e)
|