WebSocket Chat
Establish Connection
Connection URL: wss://wbs.p2p.mexc.com/ws
Required Permission: P2P Deal Order, P2P Deal Ad
Monitor connection status in real time. Reconnect when the connection is lost.
Connection Parameters
| Name | Mandatory | Description |
|---|---|---|
| listenKey | yes | Generated via Generate listenKey API |
| conversationId | yes | Obtained via Get Chat Conversation Info API |
Connection Example
wss://wbs.p2p.mexc.com/ws?listenKey=pqia91ma19a5s61cv6a81va65sd099v8a65a1&conversationId=123
Send Message
Request
{
"method": "SEND_MESSAGE",
"params": "{\"content\":\"This is a design screenshot\",\"conversationId\":50012,\"type\":2,\"imageUrl\":\"https://cdn.example.com/images/design_v3.png\",\"imageThumbUrl\":\"https://cdn.example.com/images/design_v3_thumb.jpg\",\"videoUrl\":\"\",\"fileUrl\":\"\"}"
}
Message Body Fields (JSON in params)
| Name | Type | Description |
|---|---|---|
| content | string | Message content |
| conversationId | integer | Conversation ID |
| type | integer | Message type: 1=text, 2=image, 3=video, 4=file |
| imageUrl | string | Image URL (required when type=2) |
| imageThumbUrl | string | Image thumbnail URL |
| videoUrl | string | Video URL (required when type=3) |
| fileUrl | string | File URL (required when type=4) |
Response
{
"success": true,
"method": "SEND_MESSAGE",
"msg": "success"
}
Receive Message
Server pushes messages to the client:
{
"success": true,
"msg": "success",
"method": "RECEIVE_MESSAGE",
"data": "{\"id\":1,\"content\":\"hello\",\"conversationId\":50012,\"type\":1,\"createTime\":\"2025-01-26 12:00:00\",\"self\":false,\"fromUserId\":\"abc123\",\"fromNickName\":\"Counterparty\"}"
}
Message Body Fields (JSON in data)
| Name | Type | Description |
|---|---|---|
| id | integer | Message ID |
| content | string | Message content |
| conversationId | integer | Conversation ID |
| type | integer | Message content type: 1=text, 2=image, 3=video, 4=file |
| imageUrl | string | Image URL |
| imageThumbUrl | string | Image thumbnail URL |
| videoUrl | string | Video URL |
| fileUrl | string | File URL |
| createTime | string | Send time |
| self | boolean | Whether the message was sent by self |
| fromUserId | string | Sender ID |
| fromNickName | string | Sender nickname |
Heartbeat
Send a heartbeat every 5 seconds. The server disconnects if no heartbeat is received for more than 60 seconds.
Request
{"method":"PING"}
Response
{
"success": true,
"method": "PING",
"msg": "success",
"data": "PONG"
}