npm install https://github.com/WhySoBad/tria-client
const client: Client = new Client({ log: true, credentials: { username: MAIL_ADDRESS, password: PASSWORD });
or
const client: Client = new Client({ log: true, credentials: { token: AUTH_JWT });
A client instance represents a logged in user
The credentials are null when the user logs in with an auth token
client.credentials.username; //mail address of the user
client.credentials.password; //password of the user
User auth token to send requests to the server
client.token;
Boolean whether the user is already connected to the server
client.connected;
Get the relatead ClientUser instance
client.user;
Method to connect the client to the server
client.connect().then(() => ...).catch(() => ...)
Method to disconnect the client from the server
client.disconnect().then(() => ...).catch(() => ...)
Method to log the user in [generate auth token, validate current token]
Gets called automatically in connect
client.login().then(() => ...).catch(() => ...)
Method to delete the logged in user
client.delete().then(() => ...).catch(() => ...)
Method to create a new private chat
client.createPrivateChat(participantUuid).then((chatUuid) => ...).catch(() => ...)
Method to create a new group chat
client.createGroupChat({ name: groupName,
tag: groupTag,
description: groupDescription,
type: groupType,
members: [memberUuids]}).then((chatUuid) => ...).catch(() => ...)
Method to join an existing group
client.joinGroup(groupUuid).then(() => ...).catch(() => ...)
Method to leave an existing group
client.leaveGroup(groupUuid).then(() => ...).catch(() => ...)
Method to change the password of the user
client.changePassword(oldPassword, newPassword).then(() => ...).catch(() => ...)
Method to search for other users and public group chats
client.search(searchOptions).then((results) => ...).catch(() => ...)
The user instance of the logged in user
The client which initialized the clientuser
client.user.client;
The uuid of the logged in user
client.user.uuid;
The timestamp when the user was created
client.user.createdAt;
The name of the user
client.user.name;
The tag of the user
client.user.tag;
The discription of the user
client.user.description;
The mail address of the user
client.user.mail;
The timestamp when the user was last seen
client.user.lastSeen;
Boolean whether the user is currently online
client.user.online;
The locale of the logged in user
client.user.locale;
The url to the avatar of the user
client.user.avatarURL;
The chats of the user
client.user.chats;
The color of the user
client.user.color;
Method to change the user's name
client.user.setName(newName).then(() => ...).catch(() => ...)
Method to change the user's tag
client.user.setTag(newTag).then(() => ...).catch(() => ...)
Method to change the user's description
client.user.setDescription(newDescription).then(() => ...).catch(() => ...)
Method to change the user's locale
client.user.setLocale(newLocale).then(() => ...).catch(() => ...)
Shorthand method for setName, setTag, setDescription and setLocale
Multiple parameters can be changed within one method call
client.user.setSettings(newSettings).then(() => ...).catch(() => ...)
Method to upload a new avatar
client.user.setAvatar(newAvatar).then(() => ...).catch(() => ...)
Method to delete the existing avatar
client.user.deleteAvatar().then(() => ...).catch(() => ...)
User instance representing an user
Important: The logged in user is represented by a ClientUser instance
The currently logged in client
user.client;
The uuid of the user
user.uuid;
The timestamp when the user was created
user.createdAt;
The name of the user
user.name;
The tag of the user
user.tag;
The discription of the user
user.description;
The timestamp when the user was last seen
user.lastSeen;
Boolean whether the user is currently online
user.online;
The locale of the logged in user
user.locale;
The url to the avatar of the user
user.avatarURL;
The color of the user
user.color;
Chat instance representing an user
The currently logged in client
chat.client;
Uuid of the chat
chat.uuid;
Timestamp when the chat was created
chat.createdAt;
Color of the chat
chat.color;
Type of the chat
chat.type;
Timestamp of the last message read by the logged in user in this chat
chat.lastRead;
All members of the chat
chat.members;
Boolean whether the logged in user is member of the chat
chat.writeable;
All currently fetched messages of the chat
chat.messages;
Boolean whether the last message of the chat was fetched
chat.lastFetched;
MemberLog of the chat
chat.memberLog;
Method to delete the chat
chat.delete().then(() => ...).catch(() => ...)
Method to send a message in the chat
chat.sendMessage(message).then(() => ...).catch(() => ...)
Method to fetch a specific amount of messages after a given timestamp
chat.fetchMessages(timestamp, amount).then(() => ...).catch(() => ...)
Mark messages until a given timestamp as read
chat.readUntil(timestamp).then(() => ...).catch(() => ...)
Group instance representing a group chat
Extends chat
Name of the group
group.name;
Tag of the group
group.tag;
Description of the group
group.description;
Url to the avatar of the group
group.avatarURL;
Boolean whether the group is public or private
group.public;
Boolean whether the logged in user can edit the group
group.canEditGroup;
Boolean whether the logged in user can edit group members
group.canEditMembers;
Boolean whether the logged in user can ban group members
group.canBan;
Boolean whether the logged in user can unban banned members
group.canUnban;
Boolean whether the logged in user can kick group members
group.canKick;
Boolean whether the logged in user can delete the chat
group.canDelete;
All banned members of the group
group.bannedMembers;
Method to delete the group
group.delete().then(() => ...).catch(() => ...)
Method to change the name of the group
group.setName(newName).then(() => ...).catch(() => ...)
Method to change the tag of the group
group.setTag(newTag).then(() => ...).catch(() => ...)
Method to change the description of the group
group.setDescription(newDescription).then(() => ...).catch(() => ...)
Method to change the type of the group
group.setType(newType).then(() => ...).catch(() => ...)
Shorthand method for setName, setTag, setDescription and setType
The method can edit multiple parameters with one method call
group.setSettings(newSettings).then(() => ...).catch(() => ...)
Method to change the avatar of the group
group.setAvatar(newAvatar).then(() => ...).catch(() => ...)
Method to delete the avatar of the group
group.deleteAvatar().then(() => ...).catch(() => ...)
Method to ban a group member
group.banMember(member).then(() => ...).catch(() => ...)
Method to unban a group member
group.unbanMember(userUuid).then(() => ...).catch(() => ...)
Method to kick a group member
group.kickMember(member).then(() => ...).catch(() => ...)
Method to edit a group member
group.editMember(member, options).then(() => ...).catch(() => ...)
PrivateChat instance represents a private chat
Extends chat
Participant of the private chat
chat.participant;
Member instance represents a member in a chat
User of the member
member.user;
Timestamp when the member joined the group
member.joinedAt;
Role of the member
member.role;
Owner instance represents an owner in a group
Extends member
Admin instance represents an admin in a group
Extends member
Timestamp when the admin was promoted
admin.promotedAt;
Permissions of the admin
admin.permissions;
Boolean whether the admin can ban members
admin.canBan;
Boolean whether the admin can unban banned members
admin.canUnban;
Boolean whether the admin can edit the group
admin.canEditGroup;
Boolean whether the admin can kick group members
admin.canKick;
MIT © WhySoBad