diff --git a/cloud/APIs/twilio.py b/cloud/APIs/twilio.py index b4f6d16..2c360d1 100644 --- a/cloud/APIs/twilio.py +++ b/cloud/APIs/twilio.py @@ -32,7 +32,7 @@ def send_alert_sms(to_phone: str, room_title: str, room_link: str = None, client # --- BUILD SMS CONTENT --- body = ( - f"Alert: A technical issue occurred with your equipment/microwave. " + f"Alert: A technical issue occurred with your SmartWave equipment/microwave. " f"A support chat room '{room_title}' has been created to assist you.\n\n" ) diff --git a/cloud/app.py b/cloud/app.py index ef9eea2..aff2d0e 100644 --- a/cloud/app.py +++ b/cloud/app.py @@ -214,6 +214,8 @@ def alert(): room_title = f"Support - {client_name}" room_link = None webex_status = "skipped" + # --- TWILIO SMS LOGIC --- + sms_sent = False three_minutes_ago = datetime.now(timezone.utc) - timedelta(minutes=3) @@ -260,32 +262,31 @@ def alert(): room_link = f"https://web.webex.com/spaces/{webex_room_id}" webex_status = "created_new_room" - + except Exception as e: current_app.logger.exception("Failed to create Webex support room") webex_status = f"creation_failed: {str(e)}" + + # --- SEND SMS --- + if webex_room_id and client_phone and not SAVEUP_TWILIO_API_TOKEN: + sms_sent = send_alert_sms( + to_phone=client_phone, + room_title=room_title, + room_link=room_link, + client_email=client_email + ) - # Update document with room details + # Update document with room and sms details if webex_room_id: alert_collection.update_one( {"_id": saved_alert.inserted_id}, - {"$set": {"webex_room_id": webex_room_id, "webex_room_title": room_title, "webex_room_link": room_link}} + {"$set": {"webex_room_id": webex_room_id, "webex_room_title": room_title, "webex_room_link": room_link, "sms_sent": sms_sent}} ) - - # --- SEND SMS --- - sms_sent = False - if client_phone and not SAVEUP_TWILIO_API_TOKEN: - sms_sent = send_alert_sms( - to_phone=client_phone, - room_title=room_title, - room_link=room_link, - client_email=client_email + else: # Just save the sms + alert_collection.update_one( + {"_id": saved_alert.inserted_id}, + {"$set": {"sms_sent": sms_sent}} ) - - alert_collection.update_one( - {"_id": saved_alert.inserted_id}, - {"$set": {"sms_sent": sms_sent}} - ) return jsonify({ "status": "success",