Requests
Overview
This section discusses methods for handling requests to join a channel (guild, chat, clan, and etc). As a rule, requests to join the channel owner come from other players. For example, players can send a request to join a clan or to participate in an in-game event. The channel owner can accept the membership request or reject it.
The service allows you to create the following types of requests:
gp.channels.acceptJoinRequest
- ccepting a request to joingp.channels.rejectJoinRequest
- rejection of a request to joingp.channels.fetchJoinRequests
- get a list of incoming join requests in the selected channelgp.channels.fetchMoreJoinRequests
- additionally load the list of incoming requests to join in the selected channelgp.channels.fetchSentJoinRequests
- get a list of requests sent by a player to join channelsgp.channels.fetchMoreSentJoinRequests
- additionally load the list of requests sent by the player to join the channels
Accepting a Request to Join
The player playerId: 123456
receives a request to join the channel channelId: 123
. To do this, use the gp.channels.acceptJoinRequest
method:
gp.channels.acceptJoinRequest({ channelId: 123, playerId: 123456 });
To get the result of a method call, you can subscribe to events:
gp.channels.on('acceptJoinRequest', () => {
// request received successfully
});
Execution with error:
gp.channels.on('error:acceptJoinRequest', (err) => {
// completed with an error
});
Possible errors are shown in the table below:
Basic Errors | Script Errors |
---|---|
player_not_found | empty_channel_id |
project_not_found | channel_not_found |
origin_not_allowed | access_denied |
player_banned | already_in_channel |
internal_error | channel_capacity_reached |
After sending the request, the player joins the channel and all players in the channel receive a notification about his entry:
gp.channels.on('event:join', (member) => {
// Channel ID
member.channelId;
// Joined Player ID
member.id;
// Player fields (avatar, name, custom fields)
member.state;
// Player Mute Information
member.mute;
});
Rejecting a Request to Join
Player playerId: 123456
rejects request to join channel channelId: 123
. To do this, use the gp.channels.rejectJoinRequest
method:
gp.channels.rejectJoinRequest({ channelId: 123, playerId: 123456 });
If the player - the owner of the channel rejects the request to join the channel, then a notification that someone rejected the request comes:
- to all players in the channel (if they can accept join requests)
- the player who sent the request
To get the result of a method call, you can subscribe to events:
gp.channels.on('rejectJoinRequest', () => {
// request successfully denied
});
Execution with error:
gp.channels.on('error:rejectJoinRequest', (err) => {
// completed with an error
});
Possible errors are shown in the table below:
Basic Errors | Script Errors |
---|---|
player_not_found | empty_channel_id |
project_not_found | channel_not_found |
origin_not_allowed | access_denied |
player_banned | join_request_not_found |
internal_error |
gp.channels.on('event:rejectJoinRequest', (joinRequest) => {
// Channel ID
joinRequest.channelId;
// ID of the player who requested to join
joinRequest.playerId;
});
Requests can be declined by the player who owns the channel and other players in the channel (if they are allowed to accept join requests).
Get a List of Incoming Membership Requests in the Selected Channel
To get a list of incoming join requests in the selected channel, use the method gp.channels.fetchJoinRequests
:
const response = await gp.channels.fetchJoinRequests({
// Channel ID
channelId: 123,
// how much to request at a time, max. 100
limit: 100,
// how many entries to skip, max. 10000, used for page navigation or "load more"
offset: 0
});
Mandatory access rights allowed to accept join requests
To get the result of a method call, you can subscribe to events:
gp.channels.on('fetchJoinRequests', (result) => {
result.items // array of membership requests list
result.canLoadMore // is it possible to load more requests
result.items.forEach((joinRequest) => {
// all request fields
// public fields of the player who submitted the request
joinRequest.player
joinRequest.player.id
joinRequest.player.name
joinRequest.player.avatar
// and other public fields
// date the request was sent, ISO 8601
invite.date
});
});
Execution with error:
gp.channels.on('error:fetchJoinRequests', (err) => {
// completed with an error
});
Possible errors are shown in the table below:
Basic Errors | Script Errors |
---|---|
player_not_found | empty_channel_id |
project_not_found | channel_not_found |
origin_not_allowed | access_denied |
player_banned | |
internal_error |
To additionally upload membership requests, use the convenient method gp.channels.fetchMoreJoinRequests
:
const response = await gp.channels.fetchMoreJoinRequests({
channelId: 123,
// how much to request at a time, max. 100
limit: 100,
});
To get the result of a method call, you can subscribe to events:
gp.channels.on('fetchMoreJoinRequests', (result) => {
result.items // query list array
result.canLoadMore // is it possible to load more requests
});
Execution with error:
gp.channels.on('error:fetchMoreJoinRequests', (err) => {
// completed with an error
});
Possible errors are shown in the table below:
Basic Errors | Script Errors |
---|---|
player_not_found | empty_channel_id |
project_not_found | channel_not_found |
origin_not_allowed | access_denied |
player_banned | |
internal_error |
Get a List of Requests Sent by a Player to Join
Get a list of requests sent by the player to join the various channels:
const response = await gp.channels.fetchSentJoinRequests({
// how much to request at a time, max. 100
limit: 100,
// how many entries to skip, max. 10000, used for page navigation or "load more"
offset: 0
});
To get the result of a method call, you can subscribe to events:
gp.channels.on('fetchSentJoinRequests', (result) => {
result.items // array of membership requests list
result.canLoadMore // is it possible to load more requests
result.items.forEach((joinRequest) => {
// all fields of the invite
// fields of the channel to which the other player is invited
joinRequest.channel
joinRequest.channel.id
joinRequest.channel.tags
joinRequest.channel.projectId
joinRequest.channel.capacity
joinRequest.channel.ownerId
joinRequest.channel.name
joinRequest.channel.description
joinRequest.channel.private
joinRequest.channel.visible
joinRequest.channel.hasPassword
joinRequest.channel.membersCount
// date the invitation was sent, ISO 8601
joinRequest.date
});
});
Execution with error:
gp.channels.on('error:fetchSentJoinRequests', (err) => {
// completed with an error
});
Possible errors are shown in the table below:
Basic Errors |
---|
player_not_found |
project_not_found |
origin_not_allowed |
player_banned |
internal_error |
To additionally upload membership requests, use the convenient method gp.channels.fetchMoreSentJoinRequests
:
const response = await gp.channels.fetchMoreSentJoinRequests({
// how much to request at a time, max. 100
limit: 100,
});
To get the result of a method call, you can subscribe to events:
gp.channels.on('fetchMoreSentJoinRequests', (result) => {
result.items // array of membership requests list
result.canLoadMore // is it possible to load more requests
});
Execution with error:
gp.channels.on('error:fetchMoreSentJoinRequests', (err) => {
// completed with an error
});
Possible errors are shown in the table below:
Basic Errors |
---|
player_not_found |
project_not_found |
origin_not_allowed |
player_banned |
internal_error |
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!