fix(scraper): voice body 加 departmentId/isRoom/时间窗 + sync 解析 root department_id
实测 queryWeChatVoiceList 必须带 callSource+departmentId+isRoom+startTime+endTime, 否则 200 但 data 空(0 数据)。WA callSource=4 / 微信 callSource=0,宽窗抓全量。 sync_*_voice_calls 照 sync_wechat_accounts 模式解析 _find_root_department_id。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1140,12 +1140,41 @@ def _parse_voice_rows(resp: Any) -> list[dict[str, Any]]:
|
||||
return rows if isinstance(rows, list) else []
|
||||
|
||||
|
||||
def _build_voice_body(page_num: int, page_size: int) -> dict[str, Any]:
|
||||
def _build_voice_body(
|
||||
page_num: int,
|
||||
page_size: int,
|
||||
*,
|
||||
department_id: str = "",
|
||||
call_source: str = "0",
|
||||
start: str = "2000-01-01 00:00:00",
|
||||
end: str = "2099-12-31 23:59:59",
|
||||
) -> dict[str, Any]:
|
||||
"""Build the ``queryWeChatVoiceList`` request body for a given page.
|
||||
|
||||
The live capture carries no filter parameters — just the page slice.
|
||||
Live diagnosis (2026-08-07 browser capture) confirmed the endpoint
|
||||
REQUIRES ``callSource`` + ``departmentId`` + ``isRoom`` + ``startTime`` +
|
||||
``endTime`` — omit any one and the HTTP layer returns 200 with an EMPTY
|
||||
``data.data`` array (0 rows). The WeChat variant uses
|
||||
``call_source="0"`` (the WA variant in :mod:`app.scraper.whatsapp`
|
||||
passes ``"4"``); a wide time window (2000-01-01 .. 2099-12-31) pulls
|
||||
the full history in one scrape. ``userId`` / ``sort`` / ``ids`` may
|
||||
stay empty. ``departmentId`` is omitted when blank so a test/fixture
|
||||
call without one still forms a valid body.
|
||||
"""
|
||||
return {"pageNum": page_num, "pageSize": page_size}
|
||||
body: dict[str, Any] = {
|
||||
"pageNum": page_num,
|
||||
"pageSize": page_size,
|
||||
"callSource": call_source,
|
||||
"isRoom": "0",
|
||||
"startTime": start,
|
||||
"endTime": end,
|
||||
"sort": "",
|
||||
"ids": [],
|
||||
"userId": "",
|
||||
}
|
||||
if department_id:
|
||||
body["departmentId"] = department_id
|
||||
return body
|
||||
|
||||
|
||||
def _parse_voice_start_time(value: Any) -> int | None:
|
||||
@@ -1222,6 +1251,7 @@ def _normalize_voice_call(record: dict[str, Any]) -> dict[str, Any]:
|
||||
async def scrape_wechat_voice_calls(
|
||||
client: YunkeClient,
|
||||
*,
|
||||
department_id: str = "",
|
||||
page_size: int = 50,
|
||||
) -> AsyncIterator[dict[str, Any]]:
|
||||
"""Yield normalized WeChat voice-call records from ``queryWeChatVoiceList``.
|
||||
@@ -1231,6 +1261,14 @@ async def scrape_wechat_voice_calls(
|
||||
primary stop signal), mapping each record to the ``PhoneCall`` column
|
||||
shape with ``channel="voice_call"`` plus a verbatim ``raw_json`` copy.
|
||||
|
||||
The endpoint REQUIRES ``callSource`` + ``departmentId`` + ``isRoom`` +
|
||||
a ``startTime``/``endTime`` window — without them it returns 200 + an
|
||||
empty ``data.data`` (0 rows). The orchestrator resolves the
|
||||
company-root ``department_id`` from the mirrored ``Department`` table
|
||||
(see :func:`app.sync.orchestrator.sync_wechat_voice_calls`); the
|
||||
default wide time window ``2000-01-01 .. 2099-12-31`` pulls the full
|
||||
history in one scrape and is not exposed as a parameter.
|
||||
|
||||
The envelope is the same flat shape as ``wxUser/list`` (no
|
||||
``basicResult`` wrapper): the row list and pagination fields sit directly
|
||||
under ``data`` (``data.data`` / ``data.total`` / ``data.pageNum`` /
|
||||
@@ -1241,6 +1279,10 @@ async def scrape_wechat_voice_calls(
|
||||
client:
|
||||
Authenticated :class:`YunkeClient`. Auth headers / 401 re-login are
|
||||
handled by the client.
|
||||
department_id:
|
||||
Company-root department id (the ``departmentId`` form field).
|
||||
Required by the live endpoint for non-empty results; resolved by
|
||||
the orchestrator when omitted (empty skips the field in the body).
|
||||
page_size:
|
||||
Page size to request. Defaults to 50 (a sane middle ground between
|
||||
request count and per-response payload size for this endpoint).
|
||||
@@ -1252,5 +1294,6 @@ async def scrape_wechat_voice_calls(
|
||||
parse_total=_parse_voice_total,
|
||||
parse_rows=_parse_voice_rows,
|
||||
build_body=_build_voice_body,
|
||||
department_id=department_id,
|
||||
):
|
||||
yield _normalize_voice_call(record)
|
||||
|
||||
@@ -556,14 +556,39 @@ def _parse_wa_voice_rows(resp: Any) -> list[dict[str, Any]]:
|
||||
return rows if isinstance(rows, list) else []
|
||||
|
||||
|
||||
def _build_wa_voice_body(page_num: int, page_size: int) -> dict[str, Any]:
|
||||
def _build_wa_voice_body(
|
||||
page_num: int,
|
||||
page_size: int,
|
||||
*,
|
||||
department_id: str = "",
|
||||
start: str = "2000-01-01 00:00:00",
|
||||
end: str = "2099-12-31 23:59:59",
|
||||
) -> dict[str, Any]:
|
||||
"""Build the WA ``queryWeChatVoiceList`` request body for a given page.
|
||||
|
||||
Adds ``callSource="4"`` (the WA flag; WeChat uses ``"0"``) to the
|
||||
standard ``pageNum`` / ``pageSize`` pagination pair. No filter
|
||||
parameters — the live capture carries none.
|
||||
Live diagnosis (2026-08-07 browser capture) confirmed the endpoint
|
||||
REQUIRES ``callSource`` + ``departmentId`` + ``isRoom`` + ``startTime`` +
|
||||
``endTime`` — omit any one and the HTTP layer returns 200 with an EMPTY
|
||||
``data.data`` array (0 rows). The WA variant uses ``callSource="4"``;
|
||||
a wide time window (2000-01-01 .. 2099-12-31) pulls the full history in
|
||||
one scrape (live total=608). ``userId`` / ``sort`` / ``ids`` may stay
|
||||
empty. ``departmentId`` is omitted when blank so a test/fixture call
|
||||
without one still forms a valid body.
|
||||
"""
|
||||
return {"pageNum": page_num, "pageSize": page_size, "callSource": "4"}
|
||||
body: dict[str, Any] = {
|
||||
"pageNum": page_num,
|
||||
"pageSize": page_size,
|
||||
"callSource": "4",
|
||||
"isRoom": "0",
|
||||
"startTime": start,
|
||||
"endTime": end,
|
||||
"sort": "",
|
||||
"ids": [],
|
||||
"userId": "",
|
||||
}
|
||||
if department_id:
|
||||
body["departmentId"] = department_id
|
||||
return body
|
||||
|
||||
|
||||
def _normalize_wa_voice_call(record: dict[str, Any]) -> dict[str, Any]:
|
||||
@@ -632,6 +657,7 @@ def _normalize_wa_voice_call(record: dict[str, Any]) -> dict[str, Any]:
|
||||
async def scrape_wa_voice_calls(
|
||||
client: YunkeClient,
|
||||
*,
|
||||
department_id: str = "",
|
||||
page_size: int = 50,
|
||||
) -> AsyncIterator[dict[str, Any]]:
|
||||
"""Yield normalized WhatsApp voice-call records from ``queryWeChatVoiceList``.
|
||||
@@ -644,6 +670,14 @@ async def scrape_wa_voice_calls(
|
||||
the ``PhoneCall`` column shape with ``channel="wa_voice_call"`` plus a
|
||||
verbatim ``raw_json`` copy.
|
||||
|
||||
The endpoint REQUIRES ``callSource`` + ``departmentId`` + ``isRoom`` +
|
||||
a ``startTime``/``endTime`` window — without them it returns 200 + an
|
||||
empty ``data.data`` (0 rows). The orchestrator resolves the
|
||||
company-root ``department_id`` from the mirrored ``Department`` table
|
||||
(see :func:`app.sync.orchestrator.sync_wa_voice_calls`); the default
|
||||
wide time window ``2000-01-01 .. 2099-12-31`` pulls the full history
|
||||
(live total=608) and is not exposed as a parameter.
|
||||
|
||||
The envelope is identical to the WeChat voice endpoint: rows sit under
|
||||
``data.data``, declared total under ``data.total``, pagination fields
|
||||
under ``data.pageNum`` / ``data.pageSize``. The WA-specific fields
|
||||
@@ -659,6 +693,10 @@ async def scrape_wa_voice_calls(
|
||||
client:
|
||||
Authenticated :class:`YunkeClient`. Auth headers / 401 re-login are
|
||||
handled by the client.
|
||||
department_id:
|
||||
Company-root department id (the ``departmentId`` form field).
|
||||
Required by the live endpoint for non-empty results; resolved by
|
||||
the orchestrator when omitted (empty skips the field in the body).
|
||||
page_size:
|
||||
Page size to request. Defaults to 50 (matches the WeChat voice
|
||||
scraper; a sane middle ground between request count and per-response
|
||||
@@ -671,5 +709,6 @@ async def scrape_wa_voice_calls(
|
||||
parse_total=_parse_wa_voice_total,
|
||||
parse_rows=_parse_wa_voice_rows,
|
||||
build_body=_build_wa_voice_body,
|
||||
department_id=department_id,
|
||||
):
|
||||
yield _normalize_wa_voice_call(record)
|
||||
|
||||
Reference in New Issue
Block a user