Seiue Notification
網頁的通知算通知嗎?當然 TM 不算。所以,推過來吧。
Seiue Notification → Telegram
Version: v1.0 — me/received-messages inbox, systemd, at‑most‑once delivery
This project installs a non‑intrusive sidecar that forwards your Seiue inbox messages to Telegram without touching or interfering with your existing attendance scripts. It authenticates to Seiue, polls your personal inbox endpoint, de‑duplicates messages, and delivers content (including attachments) to a Telegram chat.
1) What it does
- Logs in to Seiue via
passport.seiue.comand authorizes to obtain anaccess_tokenand youractive_reflection_id. - Polls:
GET https://api.seiue.com/chalk/me/received-messagesowner.id=<reflection_id>type=messageexpand=sender_reflectionpaginated=1sort=-published_at,-created_at- optional
readed=falseandis_cc=false
- Pushes each new message to Telegram:
- Auto‑splits long messages (Telegram 4096 char limit).
- Sends images via
sendPhoto, files viasendDocument(downloaded with auth; filename fromContent-Dispositionor URL). - Honors Telegram rate limits (
retry_after) and adds a minimum send interval.
- At‑most‑once delivery:
- Singleton lock (
.notify.lock) prevents multiple instances. - Watermark state file (
notify_state.json) tracks(last_seen_ts, last_seen_id)and a per‑IDseenmap. - First run sends one confirmation (latest item) then starts live mode, avoiding history floods (configurable).
- Singleton lock (
- Self‑healing:
- Retries on network/5xx.
- Re‑authenticates on
401/403. - Works with/without
systemd(falls back tonohup).
2) Requirements
- Linux host (Debian/Ubuntu/CentOS are fine).
python3≥ 3.7 (installer creates a venv).- Outbound connectivity to:
passport.seiue.com,chalk-c3.seiue.com,api.seiue.comapi.telegram.org
- A Telegram Bot Token and a Chat ID.
- Optional outbound proxy (supported via environment variables).
3) Quick install
The installer is idempotent. Re‑running upgrades the Python worker and restarts the service while keeping your
.env.
bash <(curl -Ls https://raw.githubusercontent.com/ieduer/bdfz/main/seiue-notify.sh)The installer will:
- Create
~/.seiue-notify/(or/root/.seiue-notify/when run as root). - Build a Python venv and install
requests,pytz,urllib3. - Prompt once for Seiue username/password, Telegram Bot Token, Telegram Chat ID, polling interval.
- Write
.env(mode600), generateseiue_notify.py, and asystemdunitseiue-notify.service. - Send a one‑shot confirmation (the latest inbox message) to Telegram.
- Start the daemon.
4) Configuration
~/.seiue-notify/.env
Example:
SEIUE_USERNAME=teacher@example.com
SEIUE_PASSWORD=***redacted***
X_SCHOOL_ID=3
X_ROLE=teacher
TELEGRAM_BOT_TOKEN=123456789:ABCDEF...
TELEGRAM_CHAT_ID=-1001234567890
# Polling & pagination
NOTIFY_POLL_SECONDS=90
MAX_LIST_PAGES=3
# Inbox scope
READ_FILTER=all # all | unread
INCLUDE_CC=false # include carbon-copied items?
# Telegram rate limiting
TELEGRAM_MIN_INTERVAL_SECS=1.5
# Startup behavior
SKIP_HISTORY_ON_FIRST_RUN=1Notes
.envis saved withchmod 600and read by the service.- Proxy pass‑through: define
HTTP_PROXY,HTTPS_PROXY,NO_PROXY(the installer injects them into the unit).
5) Service control
# status / follow logs
sudo systemctl status seiue-notify --no-pager
journalctl -u seiue-notify -f
# start / stop / restart
sudo systemctl start seiue-notify
sudo systemctl stop seiue-notify
sudo systemctl restart seiue-notifyLog files (besides journalctl):
~/.seiue-notify/logs/notify.out.log
~/.seiue-notify/logs/notify.err.logNo systemd? The installer uses:
nohup ~/.seiue-notify/run.sh >/dev/null 2>&1 &Check with:
pgrep -a -f '/\.seiue-notify/venv/bin/python .*/seiue_notify\.py'6) How it works (under the hood)
-
Auth
POST https://passport.seiue.com/login?school_id=3(account login)POST https://passport.seiue.com/authorizewithresponse_type=token
Extractsaccess_tokenandactive_reflection_id.
Sets headers:
Authorization: Bearer <token>,x-school-id: 3,x-role: teacher,x-reflection-id: <reflection_id>.
-
Inbox fetch
GET /chalk/me/received-messages?owner.id=<reflection_id>&type=message&expand=sender_reflection&paginated=1&sort=-published_at,-created_at&page=1&per_page=20
Optional:readed=false,is_cc=false.
Paginates up toMAX_LIST_PAGES. -
De‑duplication
- Keeps
(last_seen_ts, last_seen_id)watermark. - Accepts only items with
(ts,id)strictly greater. - Uses a
seenmap to guard against re‑delivery even if the watermark resets.
- Keeps
-
Telegram delivery
- Long messages are split across multiple
sendMessagecalls with(Part i/N)headers. - Files/images are fetched with the authenticated session and uploaded as
sendDocument/sendPhoto. - Handles
429viaretry_afterand enforcesTELEGRAM_MIN_INTERVAL_SECS.
- Long messages are split across multiple
7) First‑run confirmation
Right after installation, the script runs:
~/.seiue-notify/venv/bin/python ~/.seiue-notify/seiue_notify.py --confirm-once- Sends the latest inbox item (if any) to Telegram so you immediately know it works.
- Also sets the watermark to avoid re‑pushing history when the daemon starts.
If you didn’t receive the confirmation:
- Ensure you have at least one message in your Seiue inbox.
- Check credentials and network connectivity.
- See
journalctl -u seiue-notify -f.
8) Resetting the watermark (start “from now”)
rm -f ~/.seiue-notify/notify_state.json
sudo systemctl restart seiue-notifyWith SKIP_HISTORY_ON_FIRST_RUN=1, the service will skip history and resume from the latest item after restart.
9) Update / Upgrade
Simply re‑run the installer:
bash <(curl -Ls https://raw.githubusercontent.com/ieduer/bdfz/main/seiue-notify.sh)- It stops the service, refreshes the Python worker, sends a new confirmation, and restarts the daemon.
- To change credentials or chat, run with:
sudo bash seiue-notify.sh --reconfigure10) Uninstall
sudo systemctl stop seiue-notify
sudo systemctl disable seiue-notify
sudo rm -f /etc/systemd/system/seiue-notify.service
sudo systemctl daemon-reload
rm -rf ~/.seiue-notify11) Security notes
.envcontains secrets; it’s created withchmod 600.- Bot tokens and passwords are never logged.
- The service runs under the user configured by the installer (root on single‑user servers is acceptable but not required).
- Scope is limited to your inbox (
me/received-messages); it does not access others’ data.
12) Defaults & Paths
- Install dir:
~/.seiue-notify/ - Key files:
seiue_notify.py(worker).env(config)notify_state.json(watermark & seen).notify.lock(singleton)logs/notify.out.log,logs/notify.err.log
- Service:
seiue-notify.service
Quick reference
# inspect
systemctl status seiue-notify --no-pager
journalctl -u seiue-notify -f
# restart clean
rm -f ~/.seiue-notify/.notify.lock
sudo systemctl restart seiue-notify
# reset watermark (start from now)
rm -f ~/.seiue-notify/notify_state.json
sudo systemctl restart seiue-notifyThis sidecar is designed to be quiet, durable, and independent—so your attendance workflow remains untouched while your Seiue inbox arrives in Telegram in real time.