cwadayi commited on
Commit
925fff4
·
verified ·
1 Parent(s): dc81690

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -15
app.py CHANGED
@@ -26,17 +26,58 @@ handler = WebhookHandler(config.CHANNEL_SECRET)
26
  # ------------------------------------------------------------------------------
27
  @app.route("/", methods=["GET"])
28
  def home():
29
- """渲染首頁,包含說明與狀態。"""
30
- base = (config.HF_SPACE_URL or request.url_root).rstrip("/")
31
- webhook_url = f"{base}/callback"
32
- static_hint = f"{base}/static/<filename>"
33
- channel_ok = "✅" if config.CHANNEL_ACCESS_TOKEN and config.CHANNEL_SECRET else "⚠️"
34
- space_ok = "✅" if config.HF_SPACE_URL else "ℹ️"
35
-
36
- return f"""
37
  <!doctype html>
38
- <html lang="zh-Hant"><head>
39
- </html>"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  @app.route("/healthz")
42
  def healthz():
@@ -68,13 +109,9 @@ def handle_message(event):
68
  處理來自使用者的文字訊息並回覆。
69
  所有邏輯都委派給 command_handler。
70
  """
71
- # 決定用於生成圖片連結的基礎 URL
72
  base_url = request.url_root.rstrip("/")
73
-
74
- # 從處理器獲取回覆訊息
75
  reply_messages = process_message(event.message.text, base_url)
76
 
77
- # 發送回覆
78
  with ApiClient(line_config) as api_client:
79
  line_bot_api = MessagingApi(api_client)
80
  line_bot_api.reply_message_with_http_info(
@@ -82,4 +119,4 @@ def handle_message(event):
82
  reply_token=event.reply_token,
83
  messages=reply_messages
84
  )
85
- )
 
26
  # ------------------------------------------------------------------------------
27
  @app.route("/", methods=["GET"])
28
  def home():
29
+ """[修改] 渲染一個簡潔的機器人狀態首頁。"""
30
+ return """
 
 
 
 
 
 
31
  <!doctype html>
32
+ <html lang="zh-Hant">
33
+ <head>
34
+ <meta charset="utf-8">
35
+ <meta name="viewport" content="width=device-width, initial-scale=1">
36
+ <title>LINE Bot Server Status</title>
37
+ <style>
38
+ body {
39
+ background-color: #0f1115;
40
+ color: #e6e8ef;
41
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
42
+ display: flex;
43
+ justify-content: center;
44
+ align-items: center;
45
+ height: 100vh;
46
+ margin: 0;
47
+ text-align: center;
48
+ }
49
+ .container {
50
+ padding: 2rem;
51
+ }
52
+ h1 {
53
+ font-size: 2.2rem;
54
+ margin-bottom: 1rem;
55
+ color: #ffffff;
56
+ }
57
+ .status-ok {
58
+ color: #22c55e; /* Green */
59
+ }
60
+ p {
61
+ font-size: 1.1rem;
62
+ color: #9aa4b2;
63
+ line-height: 1.6;
64
+ max-width: 600px;
65
+ }
66
+ .active {
67
+ font-weight: bold;
68
+ color: #22c55e; /* Green */
69
+ }
70
+ </style>
71
+ </head>
72
+ <body>
73
+ <div class="container">
74
+ <h1><span class="status-ok">✓</span> LINE Bot Server is Running</h1>
75
+ <p>This is the backend service for the Earthquake Alert Bot.</p>
76
+ <p>The service is <span class="active">active</span> and listening for webhook events from LINE.</p>
77
+ </div>
78
+ </body>
79
+ </html>
80
+ """
81
 
82
  @app.route("/healthz")
83
  def healthz():
 
109
  處理來自使用者的文字訊息並回覆。
110
  所有邏輯都委派給 command_handler。
111
  """
 
112
  base_url = request.url_root.rstrip("/")
 
 
113
  reply_messages = process_message(event.message.text, base_url)
114
 
 
115
  with ApiClient(line_config) as api_client:
116
  line_bot_api = MessagingApi(api_client)
117
  line_bot_api.reply_message_with_http_info(
 
119
  reply_token=event.reply_token,
120
  messages=reply_messages
121
  )
122
+ )