twilio small cleanup
This commit is contained in:
@@ -32,7 +32,7 @@ def send_alert_sms(to_phone: str, room_title: str, room_link: str = None, client
|
|||||||
|
|
||||||
# --- BUILD SMS CONTENT ---
|
# --- BUILD SMS CONTENT ---
|
||||||
body = (
|
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"
|
f"A support chat room '{room_title}' has been created to assist you.\n\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+18
-17
@@ -214,6 +214,8 @@ def alert():
|
|||||||
room_title = f"Support - {client_name}"
|
room_title = f"Support - {client_name}"
|
||||||
room_link = None
|
room_link = None
|
||||||
webex_status = "skipped"
|
webex_status = "skipped"
|
||||||
|
# --- TWILIO SMS LOGIC ---
|
||||||
|
sms_sent = False
|
||||||
|
|
||||||
three_minutes_ago = datetime.now(timezone.utc) - timedelta(minutes=3)
|
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}"
|
room_link = f"https://web.webex.com/spaces/{webex_room_id}"
|
||||||
|
|
||||||
webex_status = "created_new_room"
|
webex_status = "created_new_room"
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.exception("Failed to create Webex support room")
|
current_app.logger.exception("Failed to create Webex support room")
|
||||||
webex_status = f"creation_failed: {str(e)}"
|
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:
|
if webex_room_id:
|
||||||
alert_collection.update_one(
|
alert_collection.update_one(
|
||||||
{"_id": saved_alert.inserted_id},
|
{"_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}}
|
||||||
)
|
)
|
||||||
|
else: # Just save the sms
|
||||||
# --- SEND SMS ---
|
alert_collection.update_one(
|
||||||
sms_sent = False
|
{"_id": saved_alert.inserted_id},
|
||||||
if client_phone and not SAVEUP_TWILIO_API_TOKEN:
|
{"$set": {"sms_sent": sms_sent}}
|
||||||
sms_sent = send_alert_sms(
|
|
||||||
to_phone=client_phone,
|
|
||||||
room_title=room_title,
|
|
||||||
room_link=room_link,
|
|
||||||
client_email=client_email
|
|
||||||
)
|
)
|
||||||
|
|
||||||
alert_collection.update_one(
|
|
||||||
{"_id": saved_alert.inserted_id},
|
|
||||||
{"$set": {"sms_sent": sms_sent}}
|
|
||||||
)
|
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"status": "success",
|
"status": "success",
|
||||||
|
|||||||
Reference in New Issue
Block a user