7330cd1766
Co-Authored-By: Claude <noreply@anthropic.com>
2.4 KiB
2.4 KiB
接 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
- 加
ENTITY_WHATSAPP_ACCOUNT = "whatsapp_account"+ENTITY_WHATSAPP_FRIEND = "whatsapp_friend"常量(line ~108 附近)。 - 加
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。
- 加
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)。 - import
scrape_whatsapp_accounts/scrape_whatsapp_friendsfrom app.scraper.whatsapp。
app/sync/scheduler.py
- 加
_run_wa_accounts+_run_wa_friends(thin wrappers,镜像_run_wa_voice_calls)。 ENTITY_FUNCS加"wa_accounts": _run_wa_accounts+"wa_friends": _run_wa_friends。- 日常
alljob 加 wa_accounts + wa_friends(在 wa_voice_calls 附近)。
测试
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
alljob 包含 WA accounts/friends。