Overview
Send messages to specified channels, supporting various message types including text, images, files, and more.
Request Body
Required Parameters
Base64 encoded message content
Channel type (1=personal channel, 2=group channel)
Optional Parameters
Message header information
Whether to not persist message (0=persist, 1=do not persist)
Whether to show red dot notification (0=do not show, 1=show)
Whether it’s write diffusion, generally 0, only cmd messages are 1
Client message number for deduplication and status tracking
Message expiration time (seconds), 0 means no expiration
Specified list of subscribers to receive the message (only valid for CMD messages)
curl -X POST "http://localhost:5001/message/send" \
-H "Content-Type: application/json" \
-d '{
"header": {
"no_persist": 0,
"red_dot": 1,
"sync_once": 0
},
"client_msg_no": "client_msg_123",
"from_uid": "user123",
"channel_id": "group123",
"channel_type": 2,
"expire": 0,
"payload": "SGVsbG8gV29ybGQ=",
"tag_key": "important"
}'
{
"message_id": 123456789,
"message_seq": 1001,
"client_msg_no": "client_msg_123"
}
Response Fields
Server-generated message ID
Client message number (echo)
Status Codes
| Status Code | Description |
|---|
| 200 | Message sent successfully |
| 400 | Request parameter error |
| 403 | No sending permission |
| 500 | Internal server error |
Message Type Examples
According to WuKongIM protocol specifications, here are recommended Payload structure examples:
Regular Messages
Text Message
{
"type": 1,
"content": "This is a text message"
}
Text Message (with @ functionality)
{
"type": 1,
"content": "This is a text message",
"mention": {
"all": 0,
"uids": ["1223", "2323"]
}
}
mention.all: Whether to @everyone (0=@users, 1=@everyone)
mention.uids: If all=1, this field is empty
Text Message (with reply)
{
"type": 1,
"content": "Replied to someone",
"reply": {
"root_mid": "xxx",
"message_id": "xxxx",
"message_seq": 123,
"from_uid": "xxxx",
"from_name": "xxx",
"payload": {}
}
}
Image Message
{
"type": 2,
"url": "http://xxxxx.com/xxx",
"width": 200,
"height": 320
}
GIF Message
{
"type": 3,
"url": "http://xxxxx.com/xxx",
"width": 72,
"height": 72
}
Voice Message
{
"type": 4,
"url": "http://xxxxx.com/xxx",
"timeTrad": 10
}
timeTrad: Voice duration (seconds)
File Message
{
"type": 8,
"url": "http://xxxxx.com/xxx",
"name": "xxxx.docx",
"size": 238734
}
Command Message
{
"type": 99,
"cmd": "groupUpdate",
"param": {}
}
System Messages
System message type must be greater than 1000
Create Group Chat
Message settings: NoPersist:0, RedDot:0, SyncOnce:1
{
"type": 1001,
"creator": "xxx",
"creator_name": "John",
"content": "{0} invited {1}, {2} to join the group chat",
"extra": [
{"uid": "xxx", "name": "John"},
{"uid": "xx01", "name": "Alice"},
{"uid": "xx02", "name": "Bob"}
]
}
Add Group Members
Message settings: NoPersist:0, RedDot:0, SyncOnce:1
{
"type": 1002,
"content": "{0} invited {1}, {2} to join the group chat",
"extra": [
{"uid": "xxx", "name": "John"},
{"uid": "xx01", "name": "Alice"},
{"uid": "xx02", "name": "Bob"}
]
}
Remove Group Members
Message settings: NoPersist:0, RedDot:0, SyncOnce:1
{
"type": 1003,
"content": "{0} removed {1} from the group chat",
"extra": [
{"uid": "xxx", "name": "John"},
{"uid": "xx01", "name": "Alice"}
]
}
Group Member Kicked
Message settings: NoPersist:0, RedDot:1, SyncOnce:0
{
"type": 1010,
"content": "You were removed from the group chat by {0}",
"extra": [
{"uid": "xxx", "name": "John"}
]
}
Update Group Name
Message settings: NoPersist:0, RedDot:0, SyncOnce:1
{
"type": 1005,
"content": "{0} changed the group name to \"Test Group\"",
"extra": [
{"uid": "xxx", "name": "John"}
]
}
Update Group Announcement
Message settings: NoPersist:0, RedDot:0, SyncOnce:1
{
"type": 1005,
"content": "{0} changed the group announcement to \"This is a group announcement\"",
"extra": [
{"uid": "xxx", "name": "John"}
]
}
Recall Message
Message settings: NoPersist:0, RedDot:0, SyncOnce:1
{
"type": 1006,
"message_id": "234343435",
"content": "{0} recalled a message",
"extra": [
{"uid": "xxx", "name": "John"}
]
}
Command Messages
Basic Command Message
Message settings: SyncOnce:1
{
"type": 99,
"cmd": "cmd",
"param": {}
}
Group Member Info Update
Upon receiving this message, the client should incrementally sync group member information
{
"type": 99,
"cmd": "memberUpdate",
"param": {
"group_no": "xxxx"
}
}
Red Dot Clear
Upon receiving this command, the client should clear the red dot for the corresponding conversation
{
"type": 99,
"cmd": "unreadClear",
"param": {
"channel_id": "xxxx",
"channel_type": 2
}
}
Usage Examples
// Send text message
const textMessage = {
type: 1,
content: "This is a text message"
};
const payload = btoa(JSON.stringify(textMessage));
const response = await fetch('/message/send', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
from_uid: "user123",
channel_id: "group123",
channel_type: 2,
payload: payload
})
});
Best Practices
- Message Deduplication: Use unique client_msg_no to avoid duplicate sending
- Message Queue: Add failed messages to retry queue
- Content Encoding: Ensure payload is correctly Base64 encoded
- Permission Check: Check if user has sending permission before sending
- Message Types: Strictly follow protocol specifications for correct message type numbers
- System Messages: System message types must be greater than 1000 with correct message flags
- Command Messages: Command messages should set SyncOnce:1 flag