Directed messages
Send direct messages between users.
Read time 2 minutesLast updated 2 days ago
Vivox provides directed text by using a similar process to what is used for group text. You can add players to existing text sessions, and you can send text messages directly to any user who is signed in, independent of being in a channel with them. Use directed text for short user-to-user messages, sometimes called whispers or private/direct messages, or to implement invite to channel capabilities.
Send directed messages
You can send a message to a player by usingVivoxService.Instance.SendDirectTextMessageAsync(string playerId, string message)void SendMessageAsync(string playerId){ if (string.IsNullOrEmpty(MessageInputField.text)) { return; } VivoxService.Instance.SendDirectTextMessageAsync(playerId, MessageInputField.text); MessageInputField.text = string.Empty;}
Receive directed messages
In order to receive messages from other users, theVivoxService.Instance.DirectedMessageReceivedVivoxMessage.ChannelNameVivoxMessage.FromSelf//Subscribe to this event at some point in the Vivox initialization process,//preferably before joining any channels.. . .VivoxService.Instance.DirectedMessageReceived += OnDirectedMessageReceived;. . .void OnDirectedMessageReceived(VivoxMessage message){ var senderName = message.SenderDisplayName; var senderId = message.SenderPlayerId; var messageText = message.MessageText; var timeReceived = message.ReceivedTime; var language = message.Language; var messageId = message.MessageId;}
Direct text message history
Vivox also allows for users to access the history of a direct message conversation between two players usingVivoxService.Instance.GetDirectTextMessageHistoryAsync(string playerId, int requestSize = 10, ChatHistoryQueryOptions chatHistoryQueryOptions = null)IReadOnlyCollectionChatHistoryQueryOptionsvoid FetchHistoryAsync(){ var historyMessages = await VivoxService.Instance.GetDirectTextMessageHistoryAsync(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}"); }}
Editing direct messages
Vivox allows for users to edit the text of messages they have sent into a channel usingVivoxService.Instance.EditDirectTextMessageAsync(string messageId, string newMessage)VivoxService.Instance.DirectedMessageEditedpublic async void UpdateDirectedMessageAsync(VivoxMessage messageToUpdate, string updatedMessageText){ await VivoxService.Instance.EditDirectTextMessageAsync(messageToUpdate.MessageId, updatedMessageText);}
Deleting direct messages
Vivox allows for users to delete direct messages they have sent usingVivoxService.Instance.DeleteDirectTextMessageAsync(string messageId)VivoxService.Instance.DirectedMessageDeletedpublic async void DeleteDirectMessageAsync(VivoxMessage messageToDelete){ await VivoxService.Instance.DeleteDirectTextMessageAsync(messageToDelete.MessageId)}