From 7330cd1766c17eb2d714dd4b7f3e8fc023771d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Mon, 10 Aug 2026 16:27:27 +0800 Subject: [PATCH] =?UTF-8?q?docs(spec):=20=E6=8E=A5=20WA=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=90=8C=E6=AD=A5(accounts+friends=20wiring)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- .../specs/2026-08-10-yunke-wa-sync-wiring.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 docs/superpowers/specs/2026-08-10-yunke-wa-sync-wiring.md diff --git a/docs/superpowers/specs/2026-08-10-yunke-wa-sync-wiring.md b/docs/superpowers/specs/2026-08-10-yunke-wa-sync-wiring.md new file mode 100644 index 0000000..56b1b0d --- /dev/null +++ b/docs/superpowers/specs/2026-08-10-yunke-wa-sync-wiring.md @@ -0,0 +1,38 @@ +# 接 WA 自动同步(accounts + friends) + +> 2026-08-10|scraper/orchestrator plumbing|WA accounts/friends scraper 存在但未接 orchestrator/scheduler +> WA messages(per-account 遍历)留后续(Phase 2)。 + +## 现状 +- `scrape_whatsapp_accounts(client, page_size)` / `scrape_whatsapp_friends(client, department_id, page_size)` 存在(app/scraper/whatsapp.py)。 +- `upsert_whatsapp_account`(repos.py:440)存在。检查 `upsert_whatsapp_friend` 是否存在;若不存在需加(镜像 upsert_wechat_friend)。 +- orchestrator 有 `sync_wechat_accounts`/`sync_wechat_friends`(thin wrappers→`_sync_full_rescrape`),但**无 sync_whatsapp_***。 +- scheduler ENTITY_FUNCS 有 `wa_voice_calls` 但**无 wa_accounts/wa_friends**。 +- ENTITY 常量缺 `ENTITY_WHATSAPP_ACCOUNT` / `ENTITY_WHATSAPP_FRIEND`。 + +## 改动 + +### `app/sync/orchestrator.py` +1. 加 `ENTITY_WHATSAPP_ACCOUNT = "whatsapp_account"` + `ENTITY_WHATSAPP_FRIEND = "whatsapp_friend"` 常量(line ~108 附近)。 +2. 加 `sync_whatsapp_accounts(session, client)` → `_sync_full_rescrape(entity_type=ENTITY_WHATSAPP_ACCOUNT, channel="whatsapp", scrape=lambda: scrape_whatsapp_accounts(client), upsert=upsert_whatsapp_account)`。 + > WA scraper 不需要 department_id(只需 page_size);channel 标记 whatsapp。 +3. 加 `sync_whatsapp_friends(session, client, department_id=None)` → 镜像 `sync_wechat_friends`,调 `scrape_whatsapp_friends(client, department_id=resolved)`。 + > 若 `upsert_whatsapp_friend` 不存在,加一个(镜像 `upsert_wechat_friend`——left join raw_json→structured)。 +4. import `scrape_whatsapp_accounts`/`scrape_whatsapp_friends` from app.scraper.whatsapp。 + +### `app/sync/scheduler.py` +1. 加 `_run_wa_accounts` + `_run_wa_friends`(thin wrappers,镜像 `_run_wa_voice_calls`)。 +2. `ENTITY_FUNCS` 加 `"wa_accounts": _run_wa_accounts` + `"wa_friends": _run_wa_friends`。 +3. 日常 `all` job 加 wa_accounts + wa_friends(在 wa_voice_calls 附近)。 + +### 测试 +```bash +cd yunke-server && DB_URL="sqlite+aiosqlite:///./smoke.db" .venv/Scripts/python.exe -m app.sync.cli sync --entity wa_accounts +cd yunke-server && DB_URL="sqlite+aiosqlite:///./smoke.db" .venv/Scripts/python.exe -m app.sync.cli sync --entity wa_friends +``` ++ `pytest -q` 全绿。 + +### 验收 +- `sync --entity wa_accounts` / `sync --entity wa_friends` 成功(fetched>0)。 +- `pytest -q` 全绿。 +- scheduler `all` job 包含 WA accounts/friends。