feat(scraper): WA群消息抓取(chatRecords friendUid=@g.us,chatRoomTalker=群内发送者)
- 真机探明:同 chatRecords 端点 friendUid 直接传 @g.us 群id(与微信群同套路) - 群行 chatRoomTalker=发送者@lid、keyId 有值(缺失时合成稳定主键) - file 字段直连 OSS URL 优先于 mediaName(WA群媒体 URL 现成!) - 守护循环同微信群;full_sync 加 9b 步;3 新测试,416 绿 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""Unit tests for the WA GROUP message normalizer in :mod:`scripts.scrape_via_page`
|
||||
(chatRecords with friendUid=@g.us, confirmed live 2026-08-20). Group rows carry
|
||||
chatRoomTalker = in-group sender id and a real keyId (unlike WeChat groups)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from scripts.scrape_via_page import _normalize_wa_group_message
|
||||
|
||||
OWNER = "15638182659@s.whatsapp.net"
|
||||
ROOM = "120363406490654152@g.us"
|
||||
|
||||
|
||||
def _row(**over):
|
||||
base = {
|
||||
"createTime": 1773025474000,
|
||||
"type": 1,
|
||||
"content": "hello",
|
||||
"isSend": 0,
|
||||
"keyId": "3EB0CC278FB9C73304A622",
|
||||
"uid": OWNER,
|
||||
"friendUid": ROOM,
|
||||
"chatRoomTalker": "267074588913817@lid",
|
||||
"nickName": "A**a",
|
||||
}
|
||||
base.update(over)
|
||||
return base
|
||||
|
||||
|
||||
def test_group_row_maps_sender_and_room():
|
||||
rec = _normalize_wa_group_message(_row())
|
||||
assert rec["channel"] == "whatsapp"
|
||||
assert rec["owner_account_id"] == OWNER
|
||||
assert rec["room_id"] == ROOM
|
||||
assert rec["talker_id"] == "267074588913817@lid" # 群内发送者(chatRoomTalker)
|
||||
assert rec["msg_id"] == "3EB0CC278FB9C73304A622" # keyId 有值,直接用
|
||||
assert rec["sender_name"] == "A**a"
|
||||
|
||||
|
||||
def test_keyid_missing_falls_back_to_stable_synthetic():
|
||||
rec = _normalize_wa_group_message(_row(keyId=None))
|
||||
expect = f"{OWNER}:{ROOM}:1773025474000:267074588913817@lid"
|
||||
assert rec["msg_id"] == expect
|
||||
again = _normalize_wa_group_message(_row(keyId=None))
|
||||
assert rec["msg_id"] == again["msg_id"] # 重扫幂等
|
||||
|
||||
|
||||
def test_media_url_preserved():
|
||||
url = "https://yk-whatsapp.oss-cn-beijing.aliyuncs.com/app-file/x.jpg"
|
||||
rec = _normalize_wa_group_message(_row(type=1, file=url))
|
||||
assert rec["file_url"] == url
|
||||
Reference in New Issue
Block a user