getMessages

View as MarkdownOpen in Claude
  • 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

const m = await chatClient.getMessages({ channel: "chan1" });
m.messages.length; // 23
m.messages[0]; // the most recent message
m.messages[0].member; // the sender
m.messages[0].content; // the content
m.messages[0].meta; // the metadata (if any)
m.cursor.next; // if not null, there are more messages.
// Get the next page using the cursor
const next = await chatClient.getMessages({
channel: "chan1",
cursor: {
after: m.cursor.after,
},
});