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:
gp.channels.openChat();
Open any chat by channel ID:
gp.channels.openChat({ id: 123 });
Open chat, filtering messages by tags:
gp.channels.openChat({ tags: ['trade'] });
gp.channels.openChat({ tags: ['location', 'underworld'] });
Messages in the chat will be sent including these tags automatically.
Chat opening options:
gp.channels.openChat({
// channel id
id: 123,
// message tags,
// only messages with both tags: location and underworld will be shown
tags: ['location', 'underworld']
});
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
gp.channels.on('openChat', () => {});
// Chat closed
gp.channels.on('closeChat', () => {});
// Failed to open chat
gp.channels.on('error:openChat', (err) => {
// errors can be related to access or chat retrieval
});
Check if the main chat can be displayed:
if (gp.channels.isMainChatEnabled) {
// The chat is enabled, you can show the chat button
}
Get the ID of the main chat:
gp.channels.mainChatId;
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.
gp.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 RequestYou can allow players to view a player's feed and leave messages there.
gp.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
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:
gp.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 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.
GamePush Community Telegram
: @gs_community.
For your suggestions e-mail
: [email protected]
We Wish you Success!