Views
No views yet
# Send SMS using Twilio
client = Client(TWILIO_SID, TWILIO_AUTH_TOKEN)
for contact in contacts:
if 'phone' in contact:
client.messages.create(
body=f"{message_text}\nLocation: {location}",
from_=TWILIO_PHONE_NUMBER,
to=contact['phone']
)
# Send emails using SendGrid
sg = SendGridAPIClient(SENDGRID_API_KEY)
for contact in contacts:
if 'email' in contact:
email = Mail(
from_email='your_verified_email@domain.com',
to_emails=contact['email'],
subject='Emergency Alert',
plain_text_content=f"{message_text}\nLocation: {location}"
)
sg.send(email)
return jsonify({"message": "Emergency alerts sent successfully!"}), 200
except Exception as e:
print(f"Error: {e}")
return jsonify({"error": "Failed to send alerts"}), 500