fix: whatsapp businessFriendList needs page+departmentId+type
Live validation: businessFriendList uses 'page' (not pageNum) and REQUIRES departmentId (root) + type or returns empty. Same class of bug as wxUser/list. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -203,9 +203,26 @@ def _parse_wa_friend_rows(resp: Any) -> list[dict[str, Any]]:
|
||||
return rows if isinstance(rows, list) else []
|
||||
|
||||
|
||||
def _build_wa_friend_body(page_num: int, page_size: int) -> dict[str, Any]:
|
||||
"""Build the ``businessFriendList`` request body for a given page."""
|
||||
return {"pageNum": page_num, "pageSize": page_size}
|
||||
def _build_wa_friend_body(
|
||||
page_num: int, page_size: int, *, department_id: str = ""
|
||||
) -> dict[str, Any]:
|
||||
"""Build the ``businessFriendList`` request body for a given page.
|
||||
|
||||
Live capture: ``{"searchInfo":"","friendSearchInfo":"","page":1,
|
||||
"pageSize":10,"departmentId":"<root>","type":"0"}``. Note this endpoint
|
||||
uses ``page`` (NOT ``pageNum`` like businessSalesList) and REQUIRES
|
||||
``departmentId`` (the company-root dept id) + ``type`` or it returns empty.
|
||||
"""
|
||||
body: dict[str, Any] = {
|
||||
"searchInfo": "",
|
||||
"friendSearchInfo": "",
|
||||
"page": page_num,
|
||||
"pageSize": page_size,
|
||||
"type": "0",
|
||||
}
|
||||
if department_id:
|
||||
body["departmentId"] = department_id
|
||||
return body
|
||||
|
||||
|
||||
def _normalize_whatsapp_friend(record: dict[str, Any]) -> dict[str, Any]:
|
||||
@@ -246,6 +263,7 @@ def _normalize_whatsapp_friend(record: dict[str, Any]) -> dict[str, Any]:
|
||||
async def scrape_whatsapp_friends(
|
||||
client: YunkeClient,
|
||||
*,
|
||||
department_id: str = "",
|
||||
page_size: int = 50,
|
||||
) -> AsyncIterator[dict[str, Any]]:
|
||||
"""Yield normalized WhatsApp contact records from ``businessFriendList``.
|
||||
@@ -270,6 +288,7 @@ async def scrape_whatsapp_friends(
|
||||
parse_total=_parse_wa_friend_total,
|
||||
parse_rows=_parse_wa_friend_rows,
|
||||
build_body=_build_wa_friend_body,
|
||||
department_id=department_id,
|
||||
):
|
||||
yield _normalize_whatsapp_friend(record)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user