lokesh341 commited on
Commit
188ef41
·
1 Parent(s): d761fce

Update services/salesforce_dispatcher.py

Browse files
Files changed (1) hide show
  1. services/salesforce_dispatcher.py +23 -18
services/salesforce_dispatcher.py CHANGED
@@ -1,24 +1,29 @@
1
  # services/salesforce_dispatcher.py
2
-
3
- import requests
4
  import json
 
5
 
6
- SALESFORCE_WEBHOOK_URL = "https://your-salesforce-instance/services/web-to-case"
 
 
7
 
8
- def send_to_salesforce(payload):
9
  """
10
- FAKE Salesforce integration DISABLED in HuggingFace Space demo.
11
- Replace SALESFORCE_WEBHOOK_URL later with real endpoint during production setup.
 
 
 
 
12
  """
13
- print("🚀 [Salesforce Dispatch Simulated] Would have sent:", payload)
14
- # Commenting actual POST request to avoid Space crash
15
- #
16
- # alert_type = "Intrusion" if any(d["label"] == "person" for d in payload["detections"]) else "Anomaly"
17
- # summary = {
18
- # "Alert_Type__c": alert_type,
19
- # "ThermalFlag__c": payload["thermal"],
20
- # "ShadowFlag__c": payload["shadow_issue"],
21
- # "Confidence_Score__c": max([d["score"] for d in payload["detections"]], default=0)
22
- # }
23
- # headers = {"Content-Type": "application/json"}
24
- # requests.post(SALESFORCE_WEBHOOK_URL, json=summary, headers=headers)
 
1
  # services/salesforce_dispatcher.py
 
 
2
  import json
3
+ import logging
4
 
5
+ # Configure logging
6
+ logging.basicConfig(level=logging.INFO)
7
+ logger = logging.getLogger(__name__)
8
 
9
+ def dispatch_to_salesforce(detections, timestamp):
10
  """
11
+ Dispatch detection data to Salesforce.
12
+ Args:
13
+ detections: Detection dictionary
14
+ timestamp: Timestamp of the frame
15
+ Returns:
16
+ bool: Success status
17
  """
18
+ try:
19
+ # Mock Salesforce dispatch (replace with actual Salesforce API calls)
20
+ payload = {
21
+ "timestamp": timestamp,
22
+ "detections": detections
23
+ }
24
+ logger.info(f"Dispatching to Salesforce: {json.dumps(payload, indent=2)}")
25
+ # Example: Use simple_salesforce or requests to send data to Salesforce
26
+ return True
27
+ except Exception as e:
28
+ logger.error(f"Failed to dispatch to Salesforce: {str(e)}")
29
+ return False