Chat history
Channel text message history
Vivox allows for users to access the history of a channel's text activity using VivoxService.Instance.GetChannelTextMessageHistoryAsync(string channelName, int requestSize = 10, ChatHistoryQueryOptions chatHistoryQueryOptions = null)
, with channelName
being the name of the channel to request the history of, requestSize
being the number of messages to return at a maximum (10 is the default), and chatHistoryQueryOptions
being an optional parameter which can do things like specifying a word or phrase contained in the messages, a specific PlayerId sender of the messages, or times to query before or after. More specific information on ChatHistoryQueryOption
s can be found in Chat history query options.
The messages returned in IReadOnlyCollection
are listed in order from newest message to oldest message.
Note: Chat history is stored for 7 days. If Text Evidence Management is in use, the storage period for chat history is extended to 30 days.
The following code snippet is an example of pulling at most recent 25 messages from a set LobbyChannelName, then logging the sender's display name and the message in order from oldest to newest, without using the optional ChatHistoryQueryOptions.
public async void FetchHistoryAsync()
{
var historyMessages = await VivoxService.Instance.GetChannelTextMessageHistoryAsync(LobbyChannelName, 10);
//Reversing the messages so they display from oldest to newest
var reversedMessages = historyMessages.Reverse();
foreach(VivoxMessage message in reversedMessages)
{
Debug.Log($"{message.SenderDisplayName}: {message.MessageText}");
}
}