d9060b6920
- VoiceClip model (BigInteger PK voice_clip_id, structured cols + raw_json)
- Alembic migration a1b2c3d4e5f6 (chains from 8c4f1d2a9e6b)
- scrape_voice_clips(client, user_id, *, channel, page_size) per-employee scraper
over POST /wechatweb/call/list {pageNum, pageSize, userId}; channel stamped
locally (wechat/whatsapp), startTime/endTime ms-epoch string -> int
- upsert_voice_clip repo + start_time/end_time/mp3_duration int coercion
- sync_voice_clips orchestrator: iterates distinct user_id across
WechatAccount + WhatsappAccount, stamps channel per account table
- scheduler ENTITY_FUNCS['voice_clips'] + added to daily 'all' job
- GET /api/voice-clips (user_id exact beats user_real_name fuzzy; channel;
company_code; start/end window on end_time; ordered end_time desc)
- VoiceClipOut schema + router registered in main.py
- tests: scraper (5) + API (11) = 16 new; full suite 370 green
Co-Authored-By: Claude <noreply@anthropic.com>
153 lines
5.2 KiB
Python
153 lines
5.2 KiB
Python
"""Fixture payloads for ``POST /wechatweb/call/list`` (长语音 voice_clip).
|
|
|
|
These records mirror the real field names confirmed by the 2026-08-07
|
|
Playwright capture (see spec §2): ``id`` (bigint PK) / ``userId`` /
|
|
``userRealName`` / ``wxId`` (WA=null) / ``talker`` (WA=null) / ``status`` /
|
|
``isSend`` / ``companyCode`` (企业串码) / ``startTime`` / ``endTime`` (both
|
|
ms-epoch STRINGS) / ``ossFileName`` (recording URL) / ``mp3Duration`` (秒) /
|
|
``durationFormat`` (HH:MM:SS).
|
|
|
|
The envelope is the SAME shape as ``queryWeChatVoiceList`` (rows under
|
|
``data.data``, declared total on ``data.total``)::
|
|
|
|
{"message":"调用成功","code":"10000","success":true,"traceId":"...",
|
|
"data":{"data":[...], "total":.., "pageNum":.., "pageSize":..}}
|
|
|
|
The cassette ships four records across two pages so a test can drive the
|
|
page-number paginator across the empty-page stop signal:
|
|
|
|
* page 1 -> 2 of the 4 fixture records, ``total=4``
|
|
* page 2 -> the other 2 records, ``total=4``
|
|
* (page 3 -> empty ``data`` array, served inline by the test)
|
|
|
|
Records deliberately exercise the documented mapping edges:
|
|
|
|
* ``vc_66001`` — wechat clip with start/end as ms-epoch strings, non-null
|
|
``ossFileName``, ``isSend=null`` (the WA/wechat long-clip payload carries
|
|
``isSend`` as null in the capture).
|
|
* ``vc_66002`` — clip with ``ossFileName=null`` (no recording URL).
|
|
* ``vc_66003`` — clip with ``mp3Duration=0`` + ``durationFormat="00:00:00"``.
|
|
* ``vc_66004`` — clip with a very long ``ossFileName`` URL.
|
|
"""
|
|
|
|
# Module name mirrors the upstream feature (长语音 voice_clip list).
|
|
# ruff: noqa: N999
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Capture-shaped voice-clip records (4 total across 2 pages).
|
|
# ---------------------------------------------------------------------------
|
|
|
|
VOICE_CLIP_RECORDS: list[dict[str, Any]] = [
|
|
{
|
|
# Standard wechat clip: start/end as ms-epoch strings, recording URL.
|
|
"id": 66001,
|
|
"userId": "832EC001_wechat_staff",
|
|
"userRealName": "聂玉婷",
|
|
"wxId": "wxid_staff_alice01",
|
|
"talker": None,
|
|
"status": None,
|
|
"isSend": None,
|
|
"companyCode": "8m0atd",
|
|
"startTime": "1786072733378", # ms-epoch string -> int
|
|
"endTime": "1786072926741",
|
|
"ossFileName": (
|
|
"https://yunke-pcfile.oss-cn-beijing.aliyuncs.com/wechat-call/"
|
|
"8m0atd/imei001/1786072733378_1786072926741.mp3"
|
|
),
|
|
"mp3Duration": 193,
|
|
"durationFormat": "00:03:13",
|
|
},
|
|
{
|
|
# Clip with no recording URL.
|
|
"id": 66002,
|
|
"userId": "832EC001_wechat_staff",
|
|
"userRealName": "聂玉婷",
|
|
"wxId": "wxid_staff_alice01",
|
|
"talker": None,
|
|
"status": None,
|
|
"isSend": None,
|
|
"companyCode": "8m0atd",
|
|
"startTime": "1786072926742",
|
|
"endTime": "1786072926742",
|
|
"ossFileName": None,
|
|
"mp3Duration": 0,
|
|
"durationFormat": "00:00:00",
|
|
},
|
|
{
|
|
# Clip with zero duration.
|
|
"id": 66003,
|
|
"userId": "832EC002_wechat_staff",
|
|
"userRealName": "李四",
|
|
"wxId": "wxid_staff_bob02",
|
|
"talker": None,
|
|
"status": None,
|
|
"isSend": None,
|
|
"companyCode": "8m0atd",
|
|
"startTime": "1786000000000",
|
|
"endTime": "1786000000000",
|
|
"ossFileName": (
|
|
"https://yunke-pcfile.oss-cn-beijing.aliyuncs.com/wechat-call/"
|
|
"8m0atd/imei002/1786000000000_1786000000000.mp3"
|
|
),
|
|
"mp3Duration": 0,
|
|
"durationFormat": "00:00:00",
|
|
},
|
|
{
|
|
# WA employee (userId range F33DA..., wxId=null) with a long URL.
|
|
"id": 66004,
|
|
"userId": "F33DA003_wa_staff",
|
|
"userRealName": "王五",
|
|
"wxId": None,
|
|
"talker": None,
|
|
"status": None,
|
|
"isSend": None,
|
|
"companyCode": "8m0atd",
|
|
"startTime": "1786100000000",
|
|
"endTime": "1786100123000",
|
|
"ossFileName": (
|
|
"https://yunke-pcfile.oss-cn-beijing.aliyuncs.com/wechat-call/"
|
|
"8m0atd/wa/F33DA003/1786100000000_1786100123000.mp3"
|
|
),
|
|
"mp3Duration": 123,
|
|
"durationFormat": "00:02:03",
|
|
},
|
|
]
|
|
|
|
# Default page size for the fixture (and the scraper). total=4 means the
|
|
# fixture fills exactly 2 pages of size 2 plus a terminating empty page.
|
|
TOTAL = len(VOICE_CLIP_RECORDS)
|
|
DEFAULT_PAGE_SIZE = 2
|
|
|
|
|
|
def make_voice_clip_list_response(
|
|
records: list[dict[str, Any]],
|
|
*,
|
|
total: int,
|
|
page_num: int = 1,
|
|
page_size: int = DEFAULT_PAGE_SIZE,
|
|
trace_id: str | None = None,
|
|
) -> dict[str, Any]:
|
|
"""Build a capture-shaped ``call/list`` response envelope.
|
|
|
|
Shape (rows + pagination fields directly under ``data``)::
|
|
|
|
{"message":"调用成功","code":"10000","success":true,"traceId":"...",
|
|
"data":{"data":[...], "total":.., "pageNum":.., "pageSize":..}}
|
|
"""
|
|
return {
|
|
"message": "调用成功",
|
|
"code": "10000",
|
|
"success": True,
|
|
"traceId": trace_id or f"trace-{page_num}",
|
|
"data": {
|
|
"data": list(records),
|
|
"total": total,
|
|
"pageNum": page_num,
|
|
"pageSize": page_size,
|
|
},
|
|
}
|