DeepLearning101 commited on
Commit
89658dc
·
verified ·
1 Parent(s): a2dbef0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -125,7 +125,7 @@ def handle_booking(name, tel, email, date_str, time, pax, remarks, line_id):
125
 
126
  try:
127
  supabase.table("bookings").insert(data).execute()
128
-
129
  # [LINE 通知老闆 - 新訂位]
130
  if LINE_ACCESS_TOKEN and LINE_ADMIN_ID:
131
  src = "🟢 LINE用戶" if line_id else "⚪ 訪客"
@@ -139,7 +139,16 @@ def handle_booking(name, tel, email, date_str, time, pax, remarks, line_id):
139
  f"人數:{pax}人\n"
140
  f"備註:{note}"
141
  )
142
- requests.post("https://api.line.me/v2/bot/message/push", headers={"Authorization": f"Bearer {LINE_ACCESS_TOKEN}", "Content-Type": "application/json"}, json={"to": LINE_ADMIN_ID, "messages": [{"type": "text", "text": msg}]})
 
 
 
 
 
 
 
 
 
143
 
144
  html_response = """<div style='text-align: center; color: #fff; padding: 20px; border: 1px solid #d4af37; border-radius: 8px; background: #222;'><h2 style='color: #d4af37; margin: 0;'>Request Received</h2><p style='margin: 10px 0;'>🥂 預約申請已提交</p><p style='font-size: 0.9em; color: #aaa;'>請留意 Email 確認信 或 Line 訊息。</p></div>"""
145
 
@@ -199,11 +208,13 @@ def check_confirmation(request: gr.Request):
199
  json={
200
  "to": LINE_ADMIN_ID, # 發給老闆
201
  "messages": [{"type": "text", "text": notify_msg}]
202
- }
 
203
  )
204
  except Exception as e:
205
  print(f"通知老闆失敗: {e}")
206
 
 
207
  return final_url
208
 
209
  # --- 6. 介面 ---
 
125
 
126
  try:
127
  supabase.table("bookings").insert(data).execute()
128
+
129
  # [LINE 通知老闆 - 新訂位]
130
  if LINE_ACCESS_TOKEN and LINE_ADMIN_ID:
131
  src = "🟢 LINE用戶" if line_id else "⚪ 訪客"
 
139
  f"人數:{pax}人\n"
140
  f"備註:{note}"
141
  )
142
+ # 🚀 加入 timeout 與錯誤捕捉
143
+ try:
144
+ requests.post(
145
+ "https://api.line.me/v2/bot/message/push",
146
+ headers={"Authorization": f"Bearer {LINE_ACCESS_TOKEN}", "Content-Type": "application/json"},
147
+ json={"to": LINE_ADMIN_ID, "messages": [{"type": "text", "text": msg}]},
148
+ timeout=5 # 最多等 5 秒,等不到就放棄,不要卡死系統
149
+ )
150
+ except Exception as e:
151
+ print(f"LINE 新訂位通知發送失敗 (但不影響訂位): {e}")
152
 
153
  html_response = """<div style='text-align: center; color: #fff; padding: 20px; border: 1px solid #d4af37; border-radius: 8px; background: #222;'><h2 style='color: #d4af37; margin: 0;'>Request Received</h2><p style='margin: 10px 0;'>🥂 預約申請已提交</p><p style='font-size: 0.9em; color: #aaa;'>請留意 Email 確認信 或 Line 訊息。</p></div>"""
154
 
 
208
  json={
209
  "to": LINE_ADMIN_ID, # 發給老闆
210
  "messages": [{"type": "text", "text": notify_msg}]
211
+ },
212
+ timeout=5 # 🚀 同樣加入 5 秒超時保護
213
  )
214
  except Exception as e:
215
  print(f"通知老闆失敗: {e}")
216
 
217
+
218
  return final_url
219
 
220
  # --- 6. 介面 ---