List conversations
List existing conversations
Get a list of existing group chat and DM conversations in the local database.
By default, list
returns only conversations with a consent state of allowed or unknown.
We recommend listing allowed conversations only. This ensures that spammy conversations with a consent state of unknown don't degrade the user experience.
To list all conversations regardless of consent state, use the consentStates
option and pass all three consent states.
Conversations are listed in descending order by their lastMessage
created at value. If a conversation has no messages, the conversation is ordered by its createdAt
value.
const allConversations = await client.conversations.list({ consentStates: [ConsentState.Allowed] });
const allGroups = await client.conversations.listGroups({ consentStates: [ConsentState.Allowed] });
const allDms = await client.conversations.listDms({ consentStates: [ConsentState.Allowed] });
List a user's active conversations
The isActive()
method determines whether the current user is still an active member of a group conversation. For example:
- When a user is added to a group,
isActive()
returnstrue
for that user - When a user is removed from a group,
isActive()
returnsfalse
for that user
You can use a user's isActive: true
value as a filter parameter when listing conversations. You can potentially have a separate section for "archived" or "inactive" conversations where you could use isActive: false
.