Skip to main content

Send Message

Explains how to send messages to channels.

Send Public Message

Send a message to a specific channel by calling the ChatManager.Instance.SendPublicMessage() method. The sent message is delivered to all subscribers of that channel.

Method Information

ItemContent
MethodChatManager.Instance.SendPublicMessage(string channel, string text)
CallbackOnPublicMessage(ChatUserInfo sender, string message) - Called when message is received

Parameters

ParameterTypeDescription
channelstringChannel name to send message to
textstringMessage content to send

Usage Example

using UnityEngine;
using UnityEngine.UI;

public class ChatExample : MonoBehaviour, IChatListener
{
public InputField _inputChat;
public Text _textView;

private string myChannel = "Default Channel";

public void SendMessage()
{
ChatManager.Instance.SendPublicMessage(myChannel, _inputChat.text);
_inputChat.text = "";
}

public void OnPublicMessage(ChatUserInfo sender, string message)
{
// Apply prohibited word filter to received message
Debug.Log($"[{sender.visitorName}] {ChatManager.Instance.Filter(message)}");
_textView.text += $"\n[{sender.visitorName}] {ChatManager.Instance.Filter(message)}";
}

// ... Other IChatListener method implementations
}

Send Private Message (Whisper)

Send a message only to a specific user by calling the ChatManager.Instance.SendPrivateMessage() method.

Method Information

ItemContent
MethodChatManager.Instance.SendPrivateMessage(string targetUserId, string text)
CallbackOnPrivateMessage(ChatUserInfo sender, string message) - Called when message is received

Parameters

ParameterTypeDescription
targetUserIdstringUser ID to receive message
textstringMessage content to send

Usage Example

using UnityEngine;
using UnityEngine.UI;

public class ChatExample : MonoBehaviour, IChatListener
{
public InputField _inputChat;

public void SendPrivateMessage()
{
string targetUserId = "string";
ChatManager.Instance.SendPrivateMessage(targetUserId, _inputChat.text);
}

public void OnPrivateMessage(ChatUserInfo sender, string message)
{
// Apply prohibited word filter to received whisper
Debug.Log($"[Whisper from {sender.visitorName}] {ChatManager.Instance.Filter(message)}");
}

// ... Other IChatListener method implementations
}