一個基於 LINE Messaging API + Flask 的天氣查詢聊天機器人。
目前部署於 Render,可 24/7 在線(
- Python 3.10+
- 一個 LINE Official Account 與 Messaging API Channel
- Render 帳號(可用 GitHub 登入)
確保專案包含以下檔案:
├── app.py
├── requirements.txt
├── .gitignore
└── README.md
.env 請不要上傳,敏感資訊改用 Render 的 Environment Variables。
- 登入 Render Dashboard,點選 New → Web Service
- 連結你的 GitHub Repo
- 基本設定:
- Name:
NTPU-WeatherBot - Language: Python 3
- Branch: main
- Region: Oregon (US West)
- Name:
在 Render 建立服務時,請設定:
-
Build Command
pip install -r requirements.txt
-
Start Command
gunicorn app:app --workers 1 --threads 8 --timeout 30
進入 Render → 你的服務 → Environment,新增:
LINE_CHANNEL_SECRET=你的Channel secret
LINE_CHANNEL_ACCESS_TOKEN=你的Channel access token
(這些值可在 LINE Developers Console → Messaging API → Channel settings 找到)
Render 預設會打 /healthz 來確認服務狀態,請在 app.py 加入:
@app.get("/healthz")
def health():
return "OK"- 回到 LINE Developers Console → Messaging API
- Webhook URL 填入 Render 分配的網址,例如:
https://ntpu-weatherbot.onrender.com/webhook - 點 Verify → 成功會回傳 200
- 開啟 Use webhook: Enabled
- 關閉「自動回應訊息」「歡迎訊息」避免重複回覆
- 在 LINE 加好友你的官方帳號
- 傳送訊息 → Render Logs 應該會出現
/webhook紀錄 - 你會收到機器人的回覆 🎉
- Free Plan 限制:若超過 15 分鐘沒有請求,Render 免費服務會休眠,第一次再喚醒時需要等待 30–60 秒。
- 長期穩定運行:若要 24/7 不間斷,建議升級付費方案。
- 安全性:不要把
.env上傳到 GitHub,敏感資訊請放 Render Environment Variables。
MIT