feat: add twilio whatsapp integration
Build Agents Runtime / build (push) Successful in 1m59s Details

This commit is contained in:
Deep Koluguri 2026-05-22 23:53:54 -04:00
parent fe73cad4e8
commit 65f0b96fa4
2 changed files with 29 additions and 4 deletions

View File

@ -7,3 +7,5 @@ pydantic
SQLAlchemy==2.0.29
psycopg2-binary==2.9.9
twilio==8.4.0

View File

@ -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: