Skip to content

Commit bbca9e6

Browse files
Update src/pages/[platform]/ai/conversation/history/index.mdx
Co-authored-by: Ian Saultz <[email protected]>
1 parent a87081d commit bbca9e6

File tree

1 file changed

+11
-4
lines changed
  • src/pages/[platform]/ai/conversation/history

1 file changed

+11
-4
lines changed

src/pages/[platform]/ai/conversation/history/index.mdx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,20 @@ To list all the conversations a user has you can use the `.list()` method. It wo
4747
const { data: conversations } = await client.conversations.chat.list()
4848
```
4949

50-
The conversation model has `createdAt` and `updatedAt` fields so you can sort by when the conversation was created or when it was last updated. The `updatedAt` field gets updated when new messages are sent, so you can use that to see which conversation had the most recent message.
50+
The `updatedAt` field gets updated when new messages are sent, so you can use that to see which conversation had the most recent message. Conversations retrieved via `.list()` are sorted in descending order by `updatedAt`.
51+
52+
### Pagination
53+
The result of `.list()` contains a `nextToken` property. This can be used to retrieve subsequent pages of conversations.
5154

5255
```ts
53-
const {data: conversations} = await client.conversations.chat.list();
56+
const { data: conversations, nextToken } = await client.conversations.chat.list();
5457

55-
conversations.sort((a, b) => (a.updatedAt > b.updatedAt ? -1 : 1))
56-
```
58+
// retrieve next page
59+
if (nextToken) {
60+
const { data: nextPageConversations } = await client.conversations.chat.list({
61+
nextToken
62+
});
63+
}
5764

5865
Conversations also have `name` and `metadata` fields you can use to more easily find and resume past conversations. `name` is a string and `metadata` is a JSON object so you can store any extra information you need.
5966

0 commit comments

Comments
 (0)