Get remote messages
Retrieve message history from the server for a community subchannel. Requires Community Channel Cloud Storage to be enabled.
Get remote messages
TypeScript
import { CommunitySubChannel, BaseChannel } from '@nexconn/chat';
const channel = new CommunitySubChannel('<communityId>', '<subChannelId>');
const query = BaseChannel.createMessagesQuery({
channelIdentifier: channel.identifier,
startTime: Date.now(), // Fetches messages before this timestamp
pageSize: 20, // Number of messages per page (1–100)
isAscending: false, // false: newest first (default), true: oldest first
});
const { code, data: page } = await query.loadNextPage();
if (code === 0) {
console.log('Messages:', page.data);
} else {
console.log('Failed to get messages. Code:', code);
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
channelIdentifier | ChannelIdentifier | Yes | Use channel.identifier |
startTime | number | No | Unix timestamp in milliseconds. Defines the starting point for paginated history. |
pageSize | number | No | Number of messages (1–100). Default: 20. |
isAscending | boolean | No | false for newest first, true for oldest first. Default: false. |
Pagination
Call loadNextPage() again on the same query object to fetch the next page. The query automatically tracks the last fetched position.