XianYuApis
XianYuApis is a third-party Python library that reverse-engineers the Xianyu (闲鱼 / Goofish) platform's private messaging protocol, providing a stable foundation for building AI-powered customer service agents on China's largest second-hand goods marketplace.
Xianyu (operated by Alibaba under the domain goofish.com) does not expose any official IM API. This project reverse-engineers the WebSocket private-messaging protocol (including sign signatures, base64 encoding, and Protobuf serialization) and wraps all HTTP endpoints so developers can focus on AI business logic rather than protocol internals.
Why This Exists
User DM ──► [XianYuApis] ──► Your AI Agent (LLM / RAG / rule engine) ──► auto-reply
▲ │
└──────────────── send message / image ◄────────────────────────┘
Key Features
| Module | Feature | Status |
|---|---|---|
| HTTP API | All Xianyu HTTP endpoints (sign decrypted) | Done |
| WebSocket | Real-time IM receive/send (sign + base64 + Protobuf) | Done |
| Message types | Text, image messages | Done |
| Session management | Fetch full conversation history | Done |
| Active send | Proactively message any user | Done |
| Token keep-alive | Auto-refresh login token, persistent process | Done |
| Chat history | Retrieve history with a specific user | Done |
| Item info | Fetch product/listing details | Done |
| Media upload | Upload images and send them | Done |
Project Structure
XianYuApis/
├── goofish_live.py # Main entry: WebSocket listener & reply logic (AI hook point)
├── goofish_apis.py # HTTP API wrappers (login, token refresh, item detail, publish)
├── message/
│ └── types.py # Message type definitions (TextContent / ImageContent / AudioContent)
├── utils/
│ └── goofish_utils.py # Utilities (sign generation, cookie handling, message decrypt)
├── static/
│ └── goofish_js_*.js # Reverse-engineered JS (core sign algorithm executed via execjs)
├── requirements.txt
└── Dockerfile