Channel messages
Send, receive and manage text messages in Vivox channels.
Read time 3 minutesLast updated 2 days ago
VivoxMessages can be sent into specific Vivox channels that have Text enabled using a ChatCapability of either TextOnly or TextAndAudio.
Send channel messages
You can send a message to a channel by usingVivoxService.Instance.SendChannelTextMessageAsync(string channelName, string message)channelNamemessagepublic async void SendMessageAsync(){ if (string.IsNullOrEmpty(MessageInputField.text)) { return; } VivoxService.Instance.SendChannelTextMessageAsync(LobbyChannelName, MessageInputField.text); MessageInputField.text = string.Empty;}
Receive channel messages
In order to receive messages from channels with text enabled, theVivoxService.Instance.ChannelMessageReceivedVivoxMessage.ChannelNameVivoxMessage.FromSelf//Subscribe to this event at some point in the Vivox initialization process,//preferably before joining any channels.. . .VivoxService.Instance.ChannelMessageReceived += OnChannelMessageReceived;. . .void OnChannelMessageReceived(VivoxMessage message){ var channelName = message.ChannelName; var senderName = message.SenderDisplayName; var senderId = message.SenderPlayerId; var messageText = message.MessageText; var timeReceived = message.ReceivedTime; var language = message.Language; var fromSelf = message.FromSelf; var messageId = message.MessageId;}
Channel text message history
Vivox allows for users to access the history of a channel's text activity usingVivoxService.Instance.GetChannelTextMessageHistoryAsync(string channelName, int requestSize = 10, ChatHistoryQueryOptions chatHistoryQueryOptions = null)channelNamerequestSizechatHistoryQueryOptionsChatHistoryQueryOptionIReadOnlyCollection
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}"); }}
Edit channel messages
Vivox allows users to edit the text of messages they have sent into a channel usingVivoxService.Instance.EditChannelTextMessageAsync(string channelName, string messageId, string newMessage)VivoxService.Instance.ChannelMessageEditedpublic async void UpdateChannelMessageAsync(VivoxMessage messageToUpdate, string updatedMessageText){ await VivoxService.Instance.EditChannelTextMessageAsync(messageToUpdate.ChannelName, messageToUpdate.MessageId, updatedMessageText);}
Delete channel messages
Vivox allows for users to delete messages they have sent into a channel usingVivoxService.Instance.DeleteChannelTextMessageAsync(string channelName, string messageId)VivoxService.Instance.ChannelMessageDeletedpublic async void DeleteChannelMessageAsync(VivoxMessage messageToDelete){ await VivoxService.Instance.DeleteChannelTextMessageAsync(messageToDelete.ChannelName, messageToDelete.MessageId)}