Spaces:
Runtime error
Runtime error
| from simple_salesforce import Salesforce | |
| from twilio.rest import Client | |
| from dotenv import load_dotenv | |
| import os | |
| class SalesforceDispatcher: | |
| def __init__(self): | |
| load_dotenv() | |
| self.sf = Salesforce( | |
| username=os.getenv("SF_USERNAME"), | |
| password=os.getenv("SF_PASSWORD"), | |
| security_token=os.getenv("SF_TOKEN") | |
| ) | |
| self.twilio_client = Client( | |
| os.getenv("TWILIO_SID"), | |
| os.getenv("TWILIO_TOKEN") | |
| ) | |
| self.twilio_number = os.getenv("TWILIO_NUMBER") | |
| def create_case(self, subject, description): | |
| """Create a Salesforce case.""" | |
| case = self.sf.Case.create({ | |
| "Subject": subject, | |
| "Description": description, | |
| "Status": "New", | |
| "Origin": "Web", | |
| "Priority": "High" | |
| }) | |
| return case["id"] | |
| def send_email(self, to, subject, body): | |
| """Send email notification (simulated).""" | |
| # Placeholder: Use Salesforce email service or external SMTP | |
| print(f"Sending email to {to}\nSubject: {subject}\nBody: {body}") | |
| def send_whatsapp(self, to, message): | |
| """Send WhatsApp message via Twilio.""" | |
| self.twilio_client.messages.create( | |
| body=message, | |
| from_=f"whatsapp:{self.twilio_number}", | |
| to=f"whatsapp:{to}" | |
| ) |