Download utils/sms_utils.py from anique-1/Medisync: direct link, hf CLI and curl.
- Browser
- Download file 3.17 kB
-
https://huggingface.co/spaces/anique-1/Medisync/resolve/main/utils/sms_utils.py
- Command line
-
hf download hf://spaces/anique-1/Medisync/utils/sms_utils.py
-
curl -L -o sms_utils.py https://huggingface.co/spaces/anique-1/Medisync/resolve/main/utils/sms_utils.py
3.17 kB
| import os | |
| from twilio.rest import Client | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| from utils.config_loader import get_setting | |
| load_dotenv() | |
| # Twilio vars are now dynamic | |
| def send_sms(to: str, body: str) -> str: | |
| account_sid = get_setting("TWILIO_ACCOUNT_SID") | |
| auth_token = get_setting("TWILIO_AUTH_TOKEN") | |
| twilio_number = get_setting("TWILIO_NUMBER") | |
| if not all([account_sid, auth_token, twilio_number]): | |
| print("Twilio credentials are not set.") | |
| return "" # Return empty string on failure | |
| client = Client(account_sid, auth_token) | |
| message = client.messages.create( | |
| body=body, | |
| from_=twilio_number, | |
| to=to | |
| ) | |
| return message.sid | |
| # --- SMS Templates --- | |
| ACCOUNT_VERIFICATION_SMS_TEMPLATE = ( | |
| "Welcome to the AI-Powered Medicine Dispenser System, {full_name}! " | |
| "Please verify your account using this link: {verification_link}" | |
| ) | |
| MEDICINE_ADDED_SMS_TEMPLATE = ( | |
| "Hi {full_name}, your medicine '{medicine_name}' (Dosage: {dosage}, Time: {time}) has been added to your schedule." | |
| ) | |
| MEDICINE_REMINDER_SMS_TEMPLATE = ( | |
| "Reminder: It's time to take your medicine '{medicine_name}' (Dosage: {dosage}) at {time}." | |
| ) | |
| MEDICINE_MISSED_SMS_TEMPLATE = ( | |
| "ALERT: You missed your medicine '{medicine_name}' (Dosage: {dosage}) scheduled at {time}." | |
| ) | |
| MEDICINE_UPDATED_SMS_TEMPLATE = ( | |
| "Hi {full_name}, your medicine '{medicine_name}' (Dosage: {dosage}, Time: {time}) has been UPDATED in your schedule." | |
| ) | |
| def send_account_verification_sms(to: str, full_name: str, verification_link: str) -> str: | |
| body = ACCOUNT_VERIFICATION_SMS_TEMPLATE.format(full_name=full_name, verification_link=verification_link) | |
| return send_sms(to, body) | |
| def send_medicine_added_sms(to: str, full_name: str, medicine_name: str, dosage: str, time: str) -> str: | |
| body = MEDICINE_ADDED_SMS_TEMPLATE.format( | |
| full_name=full_name, medicine_name=medicine_name, dosage=dosage, time=time | |
| ) | |
| return send_sms(to, body) | |
| def send_medicine_reminder_sms(to: str, medicine_name: str, dosage: str, time: str) -> str: | |
| body = MEDICINE_REMINDER_SMS_TEMPLATE.format( | |
| medicine_name=medicine_name, dosage=dosage, time=time | |
| ) | |
| return send_sms(to, body) | |
| def send_medicine_missed_sms(to: str, full_name: str, medicine_name: str, dosage: str, time: str) -> str: | |
| body = MEDICINE_MISSED_SMS_TEMPLATE.format( | |
| full_name=full_name, medicine_name=medicine_name, dosage=dosage, time=time | |
| ) | |
| return send_sms(to, body) | |
| def send_medicine_updated_sms(to: str, full_name: str, medicine_name: str, dosage: str, time: str) -> str: | |
| body = MEDICINE_UPDATED_SMS_TEMPLATE.format( | |
| full_name=full_name, medicine_name=medicine_name, dosage=dosage, time=time | |
| ) | |
| return send_sms(to, body) | |
| # --- Pre-order Confirmation SMS --- | |
| PREORDER_CONFIRMATION_SMS_TEMPLATE = ( | |
| "Dear {full_name}, your pre-order request has been received. Our company will contact you soon. - Medicine Dispenser Team" | |
| ) | |
| def send_preorder_confirmation_sms(to: str, full_name: str) -> str: | |
| body = PREORDER_CONFIRMATION_SMS_TEMPLATE.format(full_name=full_name) | |
| return send_sms(to, body) | |