getMessages

View as Markdown

getMessages

  • getMessages(params): Promise<{ cursor: PaginationCursor ; messages: ChatMessageEntity[] }> - See ChatMessageEntity for more details.

Returns the list of messages that were sent to the specified channel.

Parameters

NameTypeDescription
paramsObject-
params.channelstringChannel for which to retrieve the messages.
params.cursor?PaginationCursorCursor for pagination.

Returns

Promise<{ cursor: PaginationCursor ; messages: ChatMessageEntity[] }> - See ChatMessageEntity for more details.

Example

1const m = await chatClient.getMessages({ channel: "chan1" });
2
3m.messages.length; // 23
4m.messages[0]; // the most recent message
5m.messages[0].member; // the sender
6m.messages[0].content; // the content
7m.messages[0].meta; // the metadata (if any)
8
9m.cursor.next; // if not null, there are more messages.
10
11// Get the next page using the cursor
12const next = await chatClient.getMessages({
13 channel: "chan1",
14 cursor: {
15 after: m.cursor.after,
16 },
17});