getMessages

View as Markdown
  • getMessages(params): Promise<{ cursor: PagingCursor; messages: ChatMessageEntity[] }>

See PagingCursor documentation and ChatMessageEntity documentation for more details.

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

Parameters

params
objectRequired

Configuration object for getting messages

params.channel
stringRequired

Channel for which to retrieve the messages.

params.cursor
PagingCursor

Cursor for pagination. See PagingCursor for more details.

Returns

Promise<{ cursor: PagingCursor; messages: ChatMessageEntity[] }>

See PagingCursor documentation and ChatMessageEntity documentation 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});