Spaces:
Sleeping
Sleeping
chen commited on
Update app.py
Browse files25 unmodified lines262728293031323334353637383940414225 unmodified lines686970717273747576777879801 unmodified line8283848525 unmodified lines# ------------------------------------------------------------------------------@app.route("/", methods=["GET"])def home():"""渲染首頁,包含說明與狀態。"""base = (config.HF_SPACE_URL or request.url_root).rstrip("/")webhook_url = f"{base}/callback"static_hint = f"{base}/static/<filename>"channel_ok = "✅" if config.CHANNEL_ACCESS_TOKEN and config.CHANNEL_SECRET else "⚠️"space_ok = "✅" if config.HF_SPACE_URL else "ℹ️"return f"""<!doctype html><html lang="zh-Hant"><head></html>"""@app.route("/healthz")def healthz():25 unmodified lines處理來自使用者的文字訊息並回覆。所有邏輯都委派給 command_handler。"""# 決定用於生成圖片連結的基礎 URLbase_url = request.url_root.rstrip("/")# 從處理器獲取回覆訊息reply_messages = process_message(event.message.text, base_url)# 發送回覆with ApiClient(line_config) as api_client:line_bot_api = MessagingApi(api_client)line_bot_api.reply_message_with_http_info(1 unmodified linereply_token=event.reply_token,messages=reply_messages))25 unmodified lines2627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828325 unmodified lines1091101111121131141151161171 unmodified line11912012112225 unmodified lines# ------------------------------------------------------------------------------@app.route("/", methods=["GET"])def home():"""[修改] 渲染一個簡潔的機器人狀態首頁。"""return """<!doctype html><html lang="zh-Hant"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>LINE Bot Server Status</title><style>body {background-color: #0f1115;color: #e6e8ef;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;display: flex;justify-content: center;align-items: center;height: 100vh;margin: 0;text-align: center;}.container {padding: 2rem;}h1 {font-size: 2.2rem;margin-bottom: 1rem;color: #ffffff;}.status-ok {color: #22c55e; /* Green */}p {font-size: 1.1rem;color: #9aa4b2;line-height: 1.6;max-width: 600px;}.active {font-weight: bold;color: #22c55e; /* Green */}</style></head><body><div class="container"><h1><span class="status-ok">✓</span> LINE Bot Server is Running</h1><p>This is the backend service for the Earthquake Alert Bot.</p><p>The service is <span class="active">active</span> and listening for webhook events from LINE.</p></div></body></html>"""@app.route("/healthz")def healthz():25 unmodified lines處理來自使用者的文字訊息並回覆。所有邏輯都委派給 command_handler。"""base_url = request.url_root.rstrip("/")reply_messages = process_message(event.message.text, base_url)with ApiClient(line_config) as api_client:line_bot_api = MessagingApi(api_client)line_bot_api.reply_message_with_http_info(1 unmodified linereply_token=event.reply_token,messages=reply_messages))
app.py+52-15