Skip to main content

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 Request

Open the main chat:

ss.channels.openChat()

Open any chat by channel ID:

ss.channels.openChat({ id: 123 })

Open chat, filtering messages by tags:

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:

ss.channels.openChat({
// channel id
id: 123,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: ['location', 'underworld']
})
info

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:

// 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
})

Check if the main chat can be displayed:

if (ss.channels.isMainChatEnabled) {
// The chat is enabled, you can show the chat button
}

Get the ID of the main chat:

ss.channels.mainChatId

Possible errors are listed in the table below:

Basic errorsScenario errors
player_not_foundempty_channel_id
project_not_foundchannel_not_found
origin_not_allowedaccess_denied
player_banned
internal_error

Selecting the main chat

  1. Go to the control panel to the Channels section
  2. 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.
  3. Enable the main chat.

Open Personal Chat

+2-3 Request

You can give players the ability to communicate with each other through private messages.

ss.channels.openPersonalChat({
// player id
playerId: 5499172001,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: ['location', 'underworld']
})

Open Player Feed

+2-3 Request

You can allow players to view a player's feed and leave messages there.

ss.channels.openFeed({
// player id
playerId: 5499172001,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: ['location', 'underworld']
})

Detect a New Message

FREE

To 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:

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
})

You can pay attention to message.target:

  • CHANNEL: a new message appeared in the chat
  • PERSONAL: someone wrote a private message to the player
  • FEED: 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!