diff --git a/requirements.txt b/requirements.txt index cd5bf7f..1b59aee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,5 @@ pydantic SQLAlchemy==2.0.29 psycopg2-binary==2.9.9 + +twilio==8.4.0 diff --git a/src/curaflow_agent/activities.py b/src/curaflow_agent/activities.py index 85148ed..63cce8f 100644 --- a/src/curaflow_agent/activities.py +++ b/src/curaflow_agent/activities.py @@ -98,10 +98,33 @@ async def send_alert_activity(alert_data: dict) -> str: """ Mocks sending an alert to the physician. """ - # In a real app, this might send an SMS via Twilio or a push notification. - # We will just print it out. - print(f"!!! CRITICAL ALERT Triggered !!!\n{alert_data['danger_explanation']}\nRecommended Action: {alert_data['recommended_action']}") - return "Alert successfully dispatched to physician." + # Real Twilio WhatsApp Integration + from twilio.rest import Client + import traceback + + # Credentials from environment or fallbacks + account_sid = os.environ.get("TWILIO_ACCOUNT_SID", "AC601e1962dc8417ddb3ae53cd8d865020") + auth_token = os.environ.get("TWILIO_AUTH_TOKEN", "08a68571a251d6d62f60dc83fc725b5a") + twilio_from = os.environ.get("TWILIO_FROM_NUMBER", "whatsapp:+14155238886") + physician_number = os.environ.get("PHYSICIAN_WHATSAPP_NUMBER", "whatsapp:+918500176938") + + msg_body = f"🚨 *CURAFLOW CRITICAL ALERT* 🚨\n\n*Anomaly Detected:*\n{alert_data.get('danger_explanation', 'Unknown danger')}\n\n*Recommended Action:*\n{alert_data.get('recommended_action', 'Review immediately.')}" + + print(f"!!! Triggering Real Twilio WhatsApp Alert to {physician_number} !!!") + + try: + client = Client(account_sid, auth_token) + message = client.messages.create( + from_=twilio_from, + body=msg_body, + to=physician_number + ) + print(f"WhatsApp message sent successfully! SID: {message.sid}") + return f"WhatsApp alert dispatched (SID: {message.sid})" + except Exception as e: + print(f"Failed to send WhatsApp message: {str(e)}") + traceback.print_exc() + return f"Failed to dispatch WhatsApp alert: {str(e)}" @activity.defn async def save_clinical_record_activity(payload: dict) -> str: