Skip to main content
POST
/
channel
/
messagesync
curl -X POST "http://localhost:5001/channel/messagesync" \
  -H "Content-Type: application/json" \
  -d '{
    "login_uid": "user123",
    "channel_id": "group123",
    "channel_type": 2,
    "start_message_seq": 1000,
    "end_message_seq": 1100,
    "limit": 50,
    "pull_mode": 0
  }'
[
  {
    "message_id": 123456789,
    "message_seq": 1001,
    "client_msg_no": "client_msg_123",
    "from_uid": "user123",
    "channel_id": "group123",
    "channel_type": 2,
    "timestamp": 1640995200,
    "payload": "SGVsbG8gV29ybGQ="
  },
  {
    "message_id": 123456790,
    "message_seq": 1002,
    "client_msg_no": "client_msg_124",
    "from_uid": "user456",
    "channel_id": "group123",
    "channel_type": 2,
    "timestamp": 1640995260,
    "payload": "SGkgdGhlcmU="
  }
]

Overview

Sync messages from a specified channel, supporting message retrieval by sequence number range.

Request Body

Required Parameters

login_uid
string
required
Current logged-in user ID
channel_id
string
required
Channel ID
channel_type
integer
required
Channel type (1=personal channel, 2=group channel)

Optional Parameters

start_message_seq
integer
Starting message sequence number (inclusive)
end_message_seq
integer
Ending message sequence number (exclusive)
limit
integer
Maximum number of messages to return, maximum 10000
pull_mode
integer
Pull mode (0=pull down, 1=pull up)
curl -X POST "http://localhost:5001/channel/messagesync" \
  -H "Content-Type: application/json" \
  -d '{
    "login_uid": "user123",
    "channel_id": "group123",
    "channel_type": 2,
    "start_message_seq": 1000,
    "end_message_seq": 1100,
    "limit": 50,
    "pull_mode": 0
  }'
[
  {
    "message_id": 123456789,
    "message_seq": 1001,
    "client_msg_no": "client_msg_123",
    "from_uid": "user123",
    "channel_id": "group123",
    "channel_type": 2,
    "timestamp": 1640995200,
    "payload": "SGVsbG8gV29ybGQ="
  },
  {
    "message_id": 123456790,
    "message_seq": 1002,
    "client_msg_no": "client_msg_124",
    "from_uid": "user456",
    "channel_id": "group123",
    "channel_type": 2,
    "timestamp": 1640995260,
    "payload": "SGkgdGhlcmU="
  }
]

Response Fields

The response is an array of message objects, each containing:
message_id
integer
required
Message ID
message_seq
integer
required
Message sequence number
client_msg_no
string
required
Client message number
from_uid
string
required
Sender user ID
channel_id
string
required
Channel ID
channel_type
integer
required
Channel type
timestamp
integer
required
Message timestamp
payload
string
required
Base64 encoded message content

Status Codes

Status CodeDescription
200Message sync successful
400Request parameter error
403No access permission
500Internal server error

Use Cases

Chat History Loading

Load Recent Messages:
// Load last 50 messages
const messages = await syncChannelMessages({
    login_uid: "user123",
    channel_id: "group123",
    channel_type: 2,
    limit: 50,
    pull_mode: 0
});
Load Older Messages:
// Load messages before a specific sequence
const olderMessages = await syncChannelMessages({
    login_uid: "user123",
    channel_id: "group123", 
    channel_type: 2,
    end_message_seq: 1000,
    limit: 50,
    pull_mode: 1
});

Message Search and Export

Export Chat History:
async function exportChatHistory(channelId, channelType, loginUid) {
    let allMessages = [];
    let startSeq = 0;
    const batchSize = 1000;
    
    while (true) {
        const messages = await syncChannelMessages({
            login_uid: loginUid,
            channel_id: channelId,
            channel_type: channelType,
            start_message_seq: startSeq,
            limit: batchSize,
            pull_mode: 0
        });
        
        if (messages.length === 0) break;
        
        allMessages = allMessages.concat(messages);
        startSeq = messages[messages.length - 1].message_seq + 1;
    }
    
    return allMessages;
}

Offline Message Sync

Sync Missed Messages:
async function syncMissedMessages(channelId, channelType, loginUid, lastSeq) {
    const missedMessages = await syncChannelMessages({
        login_uid: loginUid,
        channel_id: channelId,
        channel_type: channelType,
        start_message_seq: lastSeq + 1,
        limit: 1000,
        pull_mode: 0
    });
    
    return missedMessages;
}

Best Practices

  1. Reasonable Range: Avoid syncing too many messages at once
  2. Pagination: Use limit parameter to control return quantity
  3. Error Handling: Handle network errors and permission errors
  4. Caching Strategy: Reasonably cache synced messages
  5. Performance Optimization: Adjust sync frequency based on actual needs
  6. Permission Check: Verify user has access to the channel before syncing
  7. Rate Limiting: Implement rate limiting to prevent excessive API calls