Send data through text messages
Learn how to send structured data using text messages.
Read time 2 minutesLast updated 2 days ago
Vivox text messages can send additional, non-messaging data through two string variables:
- Application stanza namespace
- Application stanza body
You can hide messages if you need to keep them hidden from users. For example, you are using them only to send data with no visible message. One method to accomplish this is to label your application stanza namespace accordingly. For example, you can have an application stanza namespace named "data:hidden" or "message:omit". You can then check for all messages with the same application stanza namespace.
You can access the hidden data after it is received. You can access its application stanza body by grabbing the message from the function that receives it.
Unreal application stanza body
The following examples detail how to send hidden data through text messages and access hidden data from messages in the Vivox Unreal SDK.Send hidden data in group messages
FString Message = playerInput; //Hello World!FString ApplicationStanzaNamespace = TEXT("team:color");FString ApplicationStanzaBody = TEXT("red");IChannelSession::FOnBeginSendTextCompletedDelegate SendChannelMessageCallback;SendChannelMessageCallback.BindLambda([this, channelId, Message](VivoxCoreError Error) { if (VxErrorSuccess == Error) { UE_LOG(LogVivoxGameInstance, Log, TEXT("Message sent to %s: %s \n"),*channelId.Name(), *Message); } return;});currentChannelSession.BeginSendText("", *Message, ApplicationStanzaNamespace, ApplicationStanzaBody, SendChannelMessageCallback);
Send hidden data in directed messages
FString Message = playerInput; //Hello World!FString ApplicationStanzaNamespace = TEXT("team:color");FString ApplicationStanzaBody = TEXT("red");ILoginSession::FOnBeginSendDirectedMessageCompletedDelegate SendDirectedMessageCallback;SendDirectedMessageCallback.BindLambda([this, accountName, message](VivoxCoreError error, const FString &request_id){ if (VxErrorSuccess != error) { UE_LOG(LogVivoxGameInstance, Error, TEXT("BeginSendDirectedMessage() returned %d:%s"), error, ANSI_TO_TCHAR(FVivoxCoreModule::ErrorToString(error))); } return;});currentLoginSession.BeginSendDirectedMessage(AccountId(VIVOX_VOICE_ISSUER, accountName, VIVOX_VOICE_DOMAIN), "", Message, ApplicationStanzaNamespace, ApplicationStanzaBody, SendDirectedMessageCallback);
Access hidden data from messages
if(textMessage.ApplicationStanzaNamespace == “team:color”){ if(textMessage.ApplicationStanzaBody == “red”) { //font becomes red } else if(textMessage.ApplicationStanzaBody == “blue”) { //font becomes blue } else { //font becomes grey }}