Skip to content

API 🔌

Commands are sent from the client SDK to the API server via HTTP. The client abstracts all of that for you.

Example:

client.joinChat('Welcome');

client.sendChatMessage('hello world!');

login

Begin a session with P3OL.

  • Response: HTTP Status 201

Note: If you already have an active session and attempt to login again the server will return HTTP Status 418

Usage

client.login('guest');

Log in with Screen Name

client.login('AzureDiamond', 'hunter2')

Working With Errors

For logging into an incorrect username/passwords the client will return a LOGIN_INVALID WebSocket event. However, validation errors can be caught with the login method (e.g. username is too long or password is too short).

Validation
client.login('IlIIIIIIlllIIIIll', 'hunter2').catch((e: Error) => {
  console.log(e.message); 
  // ^-- The username must not be greater than 16 characters.
});
Invalid Event
client.on('.login.invalid', () => {
  console.log('The screen name or password you have entered is invalid.');
});

Interface

login(username: string, password?: string): Promise<any>;

logoff

Begin a session with P3OL.

  • Response: HTTP Status 200

Usage

client.logoff();

Interface

logoff(): Promise<any>;

on

Register an Event callback for a WebSocket event.

Usage

client.on('.set.screen.name', (e) => {
  console.log('My screen name is: ' + e.screenName);
});

Interface

on(event: Events | string, callback: any): void;

fetchChatRooms

Fetch a list of public chat rooms. The listing of chat rooms will be sent back using the .chat.room.list event.

Usage

client.fetchChatRooms();

Interface

fetchChatRooms(): Promise<any>;

joinChatRoom

Join a public chat room on P3OL.

  • Response: HTTP Status 200

Usage

client.joinChatRoom('Welcome');

Interface

joinChatRoom(roomName: string): Promise<any>;

leaveChatRoom

Leave a chat room on P3OL.

  • Response: HTTP Status 200

Usage

client.leaveChatRoom('Welcome');

Interface

leaveChatRoom(roomName: string): Promise<any>;

sendChatMessage

Begin a session with P3OL.

  • Response: HTTP Status 201

Usage

client.sendChatMessage('Hello World!');

Interface

sendChatMessage(message: string): Promise<any>;

sendInstantMessage

Send an instant message to user.

  • Response: HTTP Status 201

Usage

client.sendInstantMessage('DomainKing', 'I have some cool .tk domains');

Interface

sendInstantMessage(screenName: string, message: string): Promise<any>;

getToken

Get your current Personal Access Token.

Usage

client.getToken();

Interface

getToken(): string | undefined;

getSessionId

Get your current API server session id.

Usage

client.getSessionId();

Interface

getSessionId(): string | undefined;

Released under the MIT License