Ready-made chats
Overview
Implementing a chat with all the nuances taken into account is very difficult. We offer using the chat embedded in the overlay.
Open the chat window
+2-3 RequestOpen the main chat:
- JavaScript
- Unity
ss.channels.openChat()
SS_Channels.OpenChat();
Open any chat by channel ID:
- JavaScript
- Unity
ss.channels.openChat({ id: 123 })
SS_Channels.OpenChat(channel_ID: 123);
Open chat, filtering messages by tags:
- JavaScript
- Unity
ss.channels.openChat({ tags: ['trade'] })
ss.channels.openChat({ tags: ['location', 'underworld'] })
SS_Channels.OpenChat(tags: "trade");
SS_Channels.OpenChat(tags: "location, underworld");
Messages in the chat will be sent including these tags automatically.
Chat opening options:
- JavaScript
- Unity
ss.channels.openChat({
// channel id
id: 123,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: ['location', 'underworld']
})
SS_Channels.OpenChat(
// channel id
channel_ID: 123,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: "location, underworld",
// On open callback
OnOpen,
// On close callback
OnClose,
// On open error callback
OnOpenError
);
The player automatically joins the channel upon opening. Make sure that everyone can join the channel and it is not password protected.
Events for tracking opening and closing of the window:
- JavaScript
- Unity
// Chat opened
ss.channels.on('openChat', () => {})
// Chat closed
ss.channels.on('closeChat', () => {})
// Failed to open chat
ss.channels.on('error:openChat', (err) => {
// errors can be related to access or chat retrieval
})
SS_Channels.OpenChat(OnOpen, OnClose, OnOpenError);
private void OnOpen() => Debug.Log("ON OPEN CHAT");
private void OnClose() => Debug.Log("ON CLOSE CHAT");
private void OnOpenError() => Debug.Log("ON OPEN CHAT: ERROR");
Check if the main chat can be displayed:
- JavaScript
- Unity
if (ss.channels.isMainChatEnabled) {
// The chat is enabled, you can show the chat button
}
if (SS_Channels.IsMainChatEnabled()) {
// The chat is enabled, you can show the chat button
}
Get the ID of the main chat:
- JavaScript
- Unity
ss.channels.mainChatId
int id = SS_Channels.MainChatId();
Debug.Log(id);
Possible errors are listed in the table below:
Basic errors | Scenario errors |
---|---|
player_not_found | empty_channel_id |
project_not_found | channel_not_found |
origin_not_allowed | access_denied |
player_banned | |
internal_error |
Selecting the main chat
- Go to the control panel to the Channels section
- Select the main chat or create a new one immediately in the chat selection. A basic chat with all settings for quick start will be created.
- Enable the main chat.
Open Personal Chat
+2-3 RequestYou can give players the ability to communicate with each other through private messages.
- JavaScript
- Unity
ss.channels.openPersonalChat({
// player id
playerId: 5499172001,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: ['location', 'underworld']
})
SS_Channels.OpenPersonalChat(
// player id
player_ID: 5499172001,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: "location, underworld"
);
Open Player Feed
+2-3 RequestYou can allow players to view a player's feed and leave messages there.
- JavaScript
- Unity
ss.channels.openFeed({
// player id
playerId: 5499172001,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: ['location', 'underworld']
})
SS_Channels.OpenFeed(
// player id
player_ID: 5499172001,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: "location, underworld"
);
Detect a New Message
FREETo save the player from constantly having to check the chat or personal messages, one can subscribe to messages in the chat.
When sending a message, all players in the channel get a notification of a new message:
- JavaScript
- Unity
ss.channels.on('event:message', (message) => {
// Channel ID
message.channelId
// Message ID
message.id
// Author ID of the message
message.authorId
// Author fields (avatar, name, custom fields)
message.player
// Message text
message.text
// Message tags
message.tags
// Date the message was sent
message.createdAt
// Message target: 'CHANNEL' | 'PERSONAL' | 'FEED'
message.target
})
// subscribe to event
private void OnEnable()
{
SS_Channels.OnMessage += OnMessage;
}
// unsubscribe from event
private void OnDisable()
{
SS_Channels.OnMessage -= OnMessage;
}
private void OnMessage(SS_Data data)
{
var messageData = data.Get<Message_Data>();
Debug.Log("ON MESSAGE EVENT: CHANNEL ID: " + messageData.channelId);
Debug.Log("ON MESSAGE EVENT: AUTHOR ID: " + messageData.authorId);
Debug.Log("ON MESSAGE EVENT: ID: " + messageData.id);
Debug.Log("ON MESSAGE EVENT: TEXT: " + messageData.text);
for (int i = 0; i < messageData.tags.Length; i++)
{
Debug.Log("ON MESSAGE EVENT: TAGS: " + messageData.tags[i]);
}
Debug.Log("ON MESSAGE EVENT: CREATED AT: " + messageData.createdAt);
Debug.Log("ON MESSAGE EVENT: PLAYER: AVATAR: " + messageData.player.avatar);
Debug.Log("ON MESSAGE EVENT: PLAYER: CREDITIALS: " + messageData.player.credentials);
Debug.Log("ON MESSAGE EVENT: PLAYER: ID: " + messageData.player.id);
Debug.Log("ON MESSAGE EVENT: PLAYER: NAME: " + messageData.player.name);
Debug.Log("ON MESSAGE EVENT: PLAYER: PLATFORM TYPE: " + messageData.player.platformType);
Debug.Log("ON MESSAGE EVENT: PLAYER: PROJECT ID: " + messageData.player.projectId);
Debug.Log("ON MESSAGE EVENT: PLAYER: SCORE: " + messageData.player.score);
}
You can pay attention to message.target
:
CHANNEL
: a new message appeared in the chatPERSONAL
: someone wrote a private message to the playerFEED
: someone wrote a message in the player's feed
Stay in Touch
Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.
SpellSync Community Telegram
: @spellsync.
For your suggestions e-mail
: [email protected]
We Wish you Success!