Documentation

Support

Vivox Unity SDK

Vivox Unity SDK

Retrieve Conversations list

How to retrieve a list of conversations for a player.
Read time 1 minuteLast updated 2 days ago

You can retrieve a user’s list of conversations. A conversation is a channel where a user has sent a message or a direct message (DM). You can use this API to populate a list of channels or DMs for a user to find their active chats. To retrieve the conversation list, sign in to the application and then use
await VivoxService.Instance.GetConversationsAsync();
to make a request. This method returns a collection of
VivoxConversation
objects, each representing either a DM or a channel conversation.
The following code is an example of how to retrieve a user’s conversation list.
// The use of `ConversationQueryOptions` is optional and the method can be called without providing it.var options = new ConversationQueryOptions(){ CutoffTime = DateTime.Now, // Point in time to fetch conversations from. Conversations joined after this timestamp will not be present in the query results. This timestamp is server side and gets converted to UTC internally. PageCursor = 1, // Parameter if you’re fetching anything but the first page. PageSize = 10 // The number of results returned per page. The default is 10.};var conversations = await VivoxService.Instance.GetConversationsAsync(options);
After you retrieve the user’s conversation list, you can parse the resulting collection of
VivoxConversation
to determine which are DMs and which are channel conversations:
foreach (VivoxConversation conversation in conversations){ switch (conversation.ConversationType) { case ConversationType.ChannelConversation: // Code for handling channel conversations. // You must be in a channel matching conversation.Name in order to fetch the message history of type ConversationType.ChannelConversation. break; case ConversationType.DirectedMessageConversation: // Code for handling DM conversations, for instance... var directMessages = await VivoxService.Instance.GetDirectTextMessageHistoryAsync(conversation.Name); // Populate UI with directMessages with another user. break; default: break; }}