The code runtime built into the server includes a module with functions to implement various logic and custom behavior, enabling you to define authoritative code and conditions on input received by clients. Learn more about it in the Server Framework documentation.
This page lists all functions available within Layerg and their respective parameters, with corresponding code samples for each. If you haven’t already, see the documentation on using the server framework.
The creation of custom tables is strongly discouraged.
Accounts
accountDeleteId
Delete an account by user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID for the account to be deleted. Must be valid UUID. |
recorded bool | false | Whether to record this deletion in the database. |
Name | Description |
---|
error error | An optional error value if an error occurred. |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
lg.accountDeleteId(userId, false);
} catch (error) {
}
accountExportId
Export account information for a specified user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID for the account to be exported. Must be valid UUID. |
Name | Description |
---|
export string | Account information for the provided user ID, in JSON format. |
error error | An optional error value if an error occurred. |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
let accountJson = lg.accountExportId(userId);
} catch (error) {
}
accountGetId
Fetch account information by user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID to fetch information for. Must be valid UUID. |
Name | Description |
---|
account lgruntime.Account | All account information including wallet, device IDs and more. |
error error | An optional error value if an error occurred. |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
let account = lg.accountGetId(userId);
} catch (error) {
}
accountsGetId
Fetch information for multiple accounts by user IDs.
Name | Default | Description |
---|
userIds []string REQUIRED | | Array of user IDs to fetch information for. Must be valid UUID. |
Returns |
---|
Name |
--- |
account lgruntime.Account[] |
error error |
let userIds = ['4ec4f126-3f9d-11e7-84ef-b7c182b36521', '6134d1cf-4b55-497f-b9e9-fc5090b76475'];
try {
let accounts = lg.accountsGetId(userIds);
} catch (error) {
}
accountUpdateId
Update an account by user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID for which the information is to be updated. Must be valid UUID. |
metadata object | | The metadata to update for this account. |
username string | | Username to be set. Must be unique. Use null if it is not being updated. |
displayName string | | Display name to be updated. Use null if it is not being updated. |
timezone string | | Timezone to be updated. Use null if it is not being updated. |
location string | | Location to be updated. Use null if it is not being updated. |
language string | | Lang tag to be updated. Use null if it is not being updated. |
avatarUrl string | | User's avatar URL. Use null if it is not being updated. |
Returns |
---|
Name |
--- |
error error |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let username = null;
let metadata = {pro: true};
let displayName = 'new display name';
let timezone = null;
let location = null;
let langTag = null;
let avatarUrl = null;
try {
lg.accountUpdateId(userId, username, displayName, timezone, location, langTag, avatarUrl, metadata);
} catch (error) {
}
Authenticate
authenticateApple
Authenticate user and create a session token using an Apple sign in token.
Name | Default | Description |
---|
token string REQUIRED | | Apple sign in token. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateApple('some-oauth-access-token', 'username', true);
} catch (error) {
}
authenticateCustom
Authenticate user and create a session token using a custom authentication managed by an external service or source not already supported by Layerg.
Name | Default | Description |
---|
id string REQUIRED | | Custom ID to use to authenticate the user. Must be between 6-128 characters. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateCustom('48656C6C6F20776F726C64', 'username', true);
} catch (error) {
}
authenticateDevice
Authenticate user and create a session token using a device identifier.
Name | Default | Description |
---|
id string REQUIRED | | Device ID to use to authenticate the user. Must be between 1-128 characters. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateDevice('48656C6C6F20776F726C64', 'username', true);
} catch (error) {
}
authenticateEmail
Authenticate user and create a session token using an email address and password.
Name | Default | Description |
---|
email string REQUIRED | | Email address to use to authenticate the user. Must be between 10-255 characters. |
password string REQUIRED | | Password to set. Must be longer than 8 characters. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateEmail('[email protected]', 'password', 'username', true);
} catch (error) {
}
authenticateFacebook
Authenticate user and create a session token using a Facebook account token.
Name | Default | Description |
---|
token string REQUIRED | | Facebook OAuth or Limited Login (JWT) access token. |
import bool | true | Whether to automatically import Facebook friends after authentication. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateFacebook('some-oauth-access-token', 'username', true);
} catch (error) {
}
authenticateFacebookInstantGame
Authenticate user and create a session token using a Facebook Instant Game.
Name | Default | Description |
---|
playerInfo string REQUIRED | | Facebook Player info. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateFacebookInstantGame('player-info', 'username', true);
} catch (error) {
}
authenticateGameCenter
Authenticate user and create a session token using Apple Game Center credentials.
Name | Default | Description |
---|
playerId string REQUIRED | | PlayerId provided by GameCenter. |
bundleId string REQUIRED | | BundleId of your app on iTunesConnect. |
timestamp int REQUIRED | | Timestamp at which Game Center authenticated the client and issued a signature. |
salt string REQUIRED | | A random string returned by Game Center authentication on client. |
signature string REQUIRED | | A signature returned by Game Center authentication on client. |
publicKeyUrl string REQUIRED | | A URL to the public key returned by Game Center authentication on client. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateGameCenter(playerId, bundleId, timestamp, salt, signature, publicKeyUrl, username, create);
} catch (error) {
}
authenticateGoogle
Authenticate user and create a session token using a Google ID token.
Name | Default | Description |
---|
token string REQUIRED | | Google OAuth access token. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateGoogle('some-id-token', 'username', true);
} catch (error) {
}
authenticateSteam
Authenticate user and create a session token using a Steam account token.
Name | Default | Description |
---|
token string REQUIRED | | Steam token. |
username string | | The user's username. If left empty, one is generated. |
import bool | true | Whether to automatically import Steam friends after authentication. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateSteam('steam-token', 'username', true);
} catch (error) {
}
authenticateTokenGenerate
Generate a Layerg session token from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID to use to generate the token. |
username string | | The user's username. If left empty, one is generated. |
expiresAt number | | UTC time in seconds when the token must expire. Defaults to server configured expiry time. |
vars | | Extra information that will be bundled in the session token. |
Name | | Description |
---|
token string | | The Layerg session token. |
validity number | | The period for which the token remains valid. |
error error | | An optional error value if an error occurred. |
let result = {} as lgruntime.TokenGenerateResult;
try {
result = lg.authenticateTokenGenerate('steam-token', 'username', true);
} catch (error) {
}
linkApple
Link Apple authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
token string REQUIRED | | Apple sign in token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.linkApple(userId, token);
} catch (error) {
}
linkCustom
Link custom authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
customId string REQUIRED | | Custom ID to be linked to the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let customId = '<CustomId>';
try {
lg.linkCustom(userId, customId);
} catch (error) {
}
linkDevice
Link device authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
deviceId string REQUIRED | | Device ID to be linked to the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let deviceId = '<Deviceid>';
try {
lg.linkDevice(userId, deviceId);
} catch (error) {
}
linkEmail
Link email authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
email string REQUIRED | | Authentication email to be linked to the user. |
password string REQUIRED | | Password to set. Must be longer than 8 characters. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let email = '[email protected]';
let password = 'correct horse battery staple'
try {
lg.linkEmail(userId, email, password);
} catch (error) {
}
linkFacebook
Link Facebook authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
username string | | If left empty, one is generated. |
token string REQUIRED | | Facebook OAuth or Limited Login (JWT) access token. |
importFriends bool | true | Whether to automatically import Facebook friends after authentication. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let username = '<Username>';
let token = '<Token>';
let importFriends = true;
try {
lg.linkFacebook(userId, username, token, importFriends);
} catch (error) {
}
linkFacebookInstantGame
Link Facebook Instant Game authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
playerInfo string REQUIRED | | Facebook player info. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let signedPlayerInfo = '<SignedPlayerInfo>';
try {
lg.linkFacebookInstantGame(userId, signedPlayerInfo);
} catch (error) {
}
linkGameCenter
Link Apple Game Center authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
playerId string REQUIRED | | Player ID provided by Game Center. |
bundleId string REQUIRED | | Bundle ID of your app on iTunesConnect. |
timestamp int REQUIRED | | Timestamp at which Game Center authenticated the client and issued a signature. |
salt string REQUIRED | | A random string returned by Game Center authentication on client. |
signature string REQUIRED | | A signature returned by Game Center authentication on client. |
publicKeyUrl string REQUIRED | | A URL to the public key returned by Game Center authentication on client. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let playerId = '<PlayerId>';
let bundleId = '<BundleId>';
let timestamp = 0;
let salt = "<Salt>";
let signature = "<Signature>";
let publicKeyUrl = "<PublicKeyUrl>";
try {
lg.linkGameCenter(userId, playerId, bundleId, timestamp, salt, signature, publicKeyUrl);
} catch (error) {
}
linkGoogle
Link Google authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
token string REQUIRED | | Google OAuth access token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.linkGoogle(userId, token);
} catch (error) {
}
linkSteam
Link Steam authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
username string | | If left empty, one is generated. |
token string REQUIRED | | Steam access token. |
importFriends bool | true | Whether to automatically import Steam friends after authentication. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let username = '<Username>';
let token = '<Token>';
let importFriends = true;
try {
lg.linkSteam(userId, username, token, importFriends);
} catch (error) {
}
unlinkApple
Unlink Apple authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
token string REQUIRED | | Apple sign in token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.unlinkApple(userId, token);
} catch (error) {
}
unlinkCustom
Unlink custom authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
customId string | | Custom ID to be unlinked from the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let customId = '<CustomId>';
try {
lg.unlinkCustom(userId, customId);
} catch (error) {
}
unlinkDevice
Unlink device authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
deviceId string REQUIRED | | Device ID to be unlinked to the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let deviceId = '<Deviceid>';
try {
lg.unlinkDevice(userId, deviceId);
} catch (error) {
}
unlinkEmail
Unlink email authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
email string | | Email to be unlinked from the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let email = '[email protected]';
try {
lg.unlinkEmail(userId, email);
} catch (error) {
}
unlinkFacebook
Unlink Facebook authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
token string | | Facebook OAuth or Limited Login (JWT) access token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.unlinkFacebook(userId, token);
} catch (error) {
}
unlinkFacebookInstantGame
Unlink Facebook Instant Game authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
playerInfo string | | Facebook player info. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let signedPlayerInfo = '<SignedPlayerInfo>';
try {
lg.unlinkFacebookInstantGame(userId, signedPlayerInfo);
} catch (error) {
}
unlinkGameCenter
Unlink Apple Game Center authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
playerId string REQUIRED | | Player ID provided by Game Center. |
bundleId string REQUIRED | | Bundle ID of your app on iTunesConnect. |
timestamp int REQUIRED | | Timestamp at which Game Center authenticated the client and issued a signature. |
salt string REQUIRED | | A random string returned by Game Center authentication on client. |
signature string REQUIRED | | A signature returned by Game Center authentication on client. |
publicKeyUrl string REQUIRED | | A URL to the public key returned by Game Center authentication on client. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let playerId = '<PlayerId>';
let bundleId = '<BundleId>';
let timestamp = 0;
let salt = "<Salt>";
let signature = "<Signature>";
let publicKeyUrl = "<PublicKeyUrl>";
try {
lg.unlinkGameCenter(userId, playerId, bundleId, timestamp, salt, signature, publicKeyUrl);
} catch (error) {
}
unlinkGoogle
Unlink Google authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
token string | | Google OAuth access token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.unlinkGoogle(userId, token);
} catch (error) {
}
unlinkSteam
Unlink Steam authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
token string | | Steam access token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.unlinkSteam(userId, token);
} catch (error) {
}
Chat
channelIdBuild
Create a channel identifier to be used in other runtime calls. Does not create a channel.
Name | Default | Description |
---|
senderId string REQUIRED | | UserID of the message sender (when applicable). Defaults to the system user if void. |
target string REQUIRED | | Can be the room name, group identifier, or another username. |
chanType lgruntime.ChannelType REQUIRED | | The type of channel, either Room (1), Direct (2), or Group (3). |
Name | | Description |
---|
channelId string | | The generated ID representing a channel. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.channelIdBuild('<SenderId>', '<RoomName>', lgruntime.ChannelType.Room);
} catch (error) {
}
channelMessageRemove
Remove a message on a realtime chat channel.
Name | Default | Description |
---|
channelId string REQUIRED | | The ID of the channel to send the message on. |
messageId string REQUIRED | | The ID of the message to remove. |
senderId string REQUIRED | | The UUID for the sender of this message. If left empty, it will be assumed that it is a system message. |
senderUsername string REQUIRED | | The username of the user to send this message as. If left empty, it will be assumed that it is a system message. |
persist bool | true | Whether to record this message in the channel history. |
Name | | Description |
---|
channelMessageRemove lgruntime.ChannelMessageAck | | Message removed ack containing the following variables: 'channelId', 'messageId', 'code', 'username', 'createTime', 'updateTime', and 'persistent'. |
error error | | An optional error value if an error occurred. |
let result: lgruntime.ChannelMessageAck;
let channelId = '<ChannelId>';
let messageId = '<MessageId>';
let senderId = '<SenderId>';
let senderUsername = 'Someone';
let persist = true;
try {
result = lg.channelMessageRemove(channelId, messageId, senderId, senderUsername, persist);
} catch (error) {
}
channelMessageSend
Send a message on a realtime chat channel.
Name | Default | Description |
---|
channelId string REQUIRED | | The ID of the channel to send the message on. |
content object REQUIRED | | Message content. |
senderId string REQUIRED | | The UUID for the sender of this message. If left empty, it will be assumed that it is a system message. |
senderUsername string REQUIRED | | The username of the user to send this message as. If left empty, it will be assumed that it is a system message. |
persist bool | true | Whether to record this message in the channel history. |
Name | | Description |
---|
channelMessageSend lgruntime.ChannelMessageAck | | Message sent ack containing the following variables: 'channelId', 'messageId', 'code', 'username', 'createTime', 'updateTime', and 'persistent'. |
error error | | An optional error value if an error occurred. |
let result: lgruntime.ChannelMessageSendAck;
let channelId = '<ChannelId>';
let content = { message: 'Hello world' };
let senderId = '<SenderId>';
let senderUsername = 'Someone';
let persist = true;
try {
result = lg.channelMessageSend(channelId, content, senderId, senderUsername, persist);
} catch (error) {
}
channelMessagesList
List messages from a realtime chat channel.
Name | Default | Description |
---|
channelId string REQUIRED | | The ID of the channel to list messages from. |
limit number | 100 | The number of messages to return per page. |
forward bool | true | Whether to list messages from oldest to newest, or newest to oldest. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
channelMessagesList lgruntime.ChannelMessageList | | Messages from the specified channel and possibly a cursor. If cursor is empty/null there are no further results. |
error error | | An optional error value if an error occurred. |
let messages = {} as lgruntime.ChannelMessageList;
try {
let channelId = "<channelId>";
messages = lg.channelMessagesList(channelId);
} catch (error) {
}
channelMessageUpdate
Update a message on a realtime chat channel.
Name | Default | Description |
---|
channelId string REQUIRED | | The ID of the channel to send the message on. |
messageId string REQUIRED | | The ID of the message to update. |
content object REQUIRED | | Message content. |
senderId string REQUIRED | | The UUID for the sender of this message. If left empty, it will be assumed that it is a system message. |
senderUsername string REQUIRED | | The username of the user to send this message as. If left empty, it will be assumed that it is a system message. |
persist bool | true | Whether to record this message in the channel history. |
Name | | Description |
---|
channelMessageUpdate lgruntime.ChannelMessageAck | | Message updated ack containing the following variables: 'channelId', 'messageId', 'code', 'username', 'createTime', 'updateTime', and 'persistent'. |
error error | | An optional error value if an error occurred. |
let channelId = '<ChannelId>';
let messageId = '<MessageId>';
let content = { message: 'Hello another world' };
let senderId = '<SenderId>';
let senderUsername = 'Someone';
let persist = true;
try {
result = lg.channelMessageUpdate(channelId, messageId, content, senderId, senderUsername, persist);
} catch (error) {
}
Events
event
Generate an event.
Name | Default | Description |
---|
event_name string REQUIRED | | The name of the event to be created. |
properties []string REQUIRED | | An array of event properties. |
ts int | | Timestamp for when event is created. |
external bool | false | Whether the event is external. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let eventName = '<EventName>';
let properties = [ 'properties' ];
let timestamp = 0;
let external = true;
try {
lg.event(eventName, properties, timestamp, external);
} catch (error) {
}
Friends
friendsAdd
Add friends to a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user to whom you want to add friends. |
username string REQUIRED | | The name of the user to whom you want to add friends. |
ids []string REQUIRED | | Table array of IDs of the users you want to add as friends. |
usernames []string REQUIRED | | Table array of usernames of the users you want to add as friends. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let username = "username";
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
let usernames = ["newfriend1", "newfriend2"];
try {
lg.friendsAdd(userId, username, userIds, usernames);
} catch (error) {
}
friendsBlock
Block friends for a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user for whom you want to block friends. |
username string REQUIRED | | The name of the user for whom you want to block friends. |
ids []string REQUIRED | | Table array of IDs of the users you want to block as friends. |
usernames []string REQUIRED | | Table array of usernames of the users you want to block as friends. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let username = "username";
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
let usernames = ["exfriend1", "exfriend2"];
try {
lg.friendsBlock(userId, username, userIds, usernames);
} catch (error) {
}
friendsDelete
Delete friends from a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user from whom you want to delete friends. |
username string REQUIRED | | The name of the user from whom you want to delete friends. |
ids []string REQUIRED | | Table array of IDs of the users you want to delete as friends. |
usernames []string REQUIRED | | Table array of usernames of the users you want to delete as friends. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let username = "username";
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
let usernames = ["exfriend1", "exfriend2"];
try {
lg.friendsDelete(userId, username, userIds, usernames);
} catch (error) {
}
friendsList
List all friends, invites, invited, and blocked which belong to a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user whose friends, invites, invited, and blocked you want to list. |
limit number | 100 | The number of friends to retrieve in this page of results. No more than 100 limit allowed per result. |
state number | | The state of the friendship with the user. If unspecified this returns friends in all states for the user. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
friends lgruntime.FriendList | | The user information for users that are friends of the current user. |
cursor string | | An optional next page cursor that can be used to retrieve the next page of records (if any). Will be set to "" or null when fetching last available page. |
error error | | An optional error value if an error occurred. |
let friends = {} as lgruntime.FriendList;
try {
let userId = 'b1aafe16-7540-11e7-9738-13777fcc7cd8';
let limit = 100;
let state = 0;
friends = lg.friendsList(userId, limit, state);
} catch (error) {
}
friendsOfFriendsList
List all friends of friends of a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user whose friends of friends you want to list. |
limit number | 10 | The number of friends to retrieve in this page of results. No more than 100 limit allowed per result. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
friends lgruntime.FriendsOfFriendsList | | The user information for users that are friends of friends of the current user. |
cursor string | | An optional next page cursor that can be used to retrieve the next page of records (if any). Will be set to "" or null when fetching last available page. |
error error | | An optional error value if an error occurred. |
let friends = {} as lgruntime.FriendList;
try {
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let limit = 100;
friends = lg.friendsOfFriendsList(userId, limit);
} catch (error) {
}
Groups
groupCreate
Setup a group with various configuration settings. The group will be created if they don't exist or fail if the group name is taken.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be associated as the group superadmin. |
name string REQUIRED | | Group name, must be unique. |
creatorId string | | The user ID to be associated as creator. If not set or nil/null, system user will be set. |
langTag string | | Group language. |
description string | | Group description, can be left empty as nil/null. |
avatarUrl string | | URL to the group avatar, can be left empty as nil/null. |
open bool | false | Whether the group is for anyone to join, or members will need to send invitations to join. |
metadata object | | Custom information to store for this group. Can be left empty as nil/null. |
maxCount number | 100 | Maximum number of members to have in the group. |
Name | | Description |
---|
createGroup lgruntime.Group | | The groupId of the newly created group. |
error error | | An optional error value if an error occurred. |
let userId = 'dcb891ea-a311-4681-9213-6741351c9994';
let creatorId = 'dcb891ea-a311-4681-9213-6741351c9994';
let name = 'Some unique group name';
let description = 'My awesome group.';
let lang = 'en';
let open = true;
let avatarURL = 'url://somelink';
let metadata = { custom_field: 'some_value' };
let maxCount = 100;
let group = {} as lgruntime.Group;
try {
group = lg.groupCreate(userId, name, creatorId, lang, description, avatarURL, open, metadata, maxCount);
} catch (error) {
}
groupDelete
Delete a group.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group to delete. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
try {
lg.groupDelete('f00fa79a-750f-11e7-8626-0fb79f45ff97');
} catch (error) {
}
groupsGetId
Fetch one or more groups by their ID.
Name | Default | Description |
---|
groupIds string[] REQUIRED | | An array of strings of the IDs for the groups to get. |
Name | | Description |
---|
getGroups lgruntime.Group[] | | An array of groups with their fields. |
error error | | An optional error value if an error occurred. |
let groups: lgruntime.Group[];
try {
let groupIds = ['dcb891ea-a311-4681-9213-6741351c9994'];
groups = lg.groupsGetId(groupIds);
} catch (error) {
}
groupsGetRandom
Fetch one or more groups randomly.
Name | Default | Description |
---|
count number REQUIRED | | The number of groups to fetch. |
Name | | Description |
---|
groups lgruntime.Group[] | | A list of group record objects. |
error error | | An optional error value if an error occurred. |
groupsList
Find groups based on the entered criteria.
Name | Default | Description |
---|
name string REQUIRED | | Search for groups that contain this value in their name. |
langTag string | | Filter based upon the entered language tag. |
members number | | Search by number of group members. |
open bool | | Filter based on whether groups are Open or Closed. |
limit number | 100 | Return only the required number of groups denoted by this limit value. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
groups lgruntime.GroupList | | A list of groups. |
cursor string | | An optional next page cursor that can be used to retrieve the next page of records (if any). Will be set to "" or null when fetching last available page. |
error error | | An optional error value if an error occurred. |
let groupName = "LayerG";
let langTag = "en";
let members = 10;
let open = true;
let limit = 100;
let results: lgruntime.GroupList = {};
try {
results = lg.groupsList(groupName, langTag, open, members, limit);
} catch (error) {
}
groupUpdate
Update a group with various configuration settings. The group which is updated can change some or all of its fields.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group to update. |
userId string REQUIRED | | User ID calling the update operation for permission checking. Set as nil to enact the changes as the system user. |
name string | | Group name, can be empty if not changed. |
creatorId string | | The user ID to be associated as creator. Can be empty if not changed. |
langTag string | | Group language. Empty if not updated. |
description string | | Group description, can be left empty if not updated. |
avatarUrl string | | URL to the group avatar, can be left empty if not updated. |
open bool | | Whether the group is for anyone to join or not. |
metadata object | | Custom information to store for this group. Use nil if field is not being updated. |
maxCount number | | Maximum number of members to have in the group. Use 0, nil/null if field is not being updated. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let metadata = { someField: 'some value' };
let groupId = 'f00fa79a-750f-11e7-8626-0fb79f45ff97';
let description = 'An updated description';
try {
lg.groupUpdate(groupId, null, null, null, null, description, null, true, metadata);
} catch (error) {
}
groupUserJoin