To create a room, you need to be authenticated
POST /rooms
{
"users": uuid[],
"apartment_id": number|null
}{
"error_message": null|string,
"data": number | null
}GET /rooms
Returns a list of room object with the last sent message.
{
"error_message": null|string,
"data": {
"room_id": number,
"participants_id":uuid[],
"apartment_id": null|int,
"is_owner": boolean,
"last_message": {
"room_id": int,
"message": string,
"sender_id": string,
"created_at": string
}
}[]
}PUT /rooms
{
"room_id": number,
"users_to_add": uuid[],
"users_to_remove": uuid[]
}{
"error_message": null|string,
"data": null
} DELETE /rooms/:id
{
"error_message": null|string,
"data": null
}GET /rooms/:id
{
"apartment_id": null|int,
"created_at": string,
"messages": {
"id": int,
"room_id": int,
"message": string,
"sender_id": uuid,
"created_at": string
}[],
"owner_id": uuid,
"participants_id": uuid[],
"room_id": int
}Connection to the chat is simple, you just need to connect via standard websocket (NO SOCKET IO) and have a param for the token (must be the user's supabase token) ex:
ws://plic-chat.prout:3030?token=eyJhb...
To send a message please follow the following format:
CommandType
| Type | Description |
|---|---|
| SendMessage | Allow you to send a message |
Data
| Data Associated Type | DataType |
|---|---|
| SendMessage | MsgSendData |
{
"type": CommandType,
"data": json
}{
"room_id": int,
"message": string,
"message_temp_id": front-generated-string
}{
"type": ResponseType,
"data": ResponseDataType
}Response Types
| Type Name | Description |
|---|---|
| Disconnection | Disconnected from server see data/code for more info |
| MessageReceived | You received a message, check data |
| MessageSentConfirmation | Check data to check if onw of the message you sent was confirmed |
{
"type": "MessageReceived",
"data": {
"room_id": int,
"sender_id": string, (Supabase ID)
"message": string
}
}{
"type": "MessageSentConfirmation",
"data": {
"confirmed": bool,
"reason": string,
"message_id": string
}
}| Code | Constant Name | Description |
|---|---|---|
| 4001 | CloseNoAuthToken |
No authentication token provided |
| 4002 | CloseInvalidToken |
Token validation failed |
| 4003 | CloseAFK |
User has been asked to be disconnected from the PHC |
| 4004 | CloseAdminAction |
User got disconnected because an admin decided |
| 4005 | CloseBanned |
User is Banned |
| 4006 | ServerError |
Server error occurred |
| 4007 | ServerShutdown |
Server is shutting down |
| 4008 | CloseNewDevice |
New device connection |
| 4009 | ConnectionClosed |
Connection closed |
| 4010 | BadMessageStructure |
Bad message structure |
| 4011 | HatefullSpeach |
Hateful speech or fake information is not permitted on Swappart |
| 4012 | UnAuthorizedAction |
User did something unauthorized within the chat |
Note: These are application-specific close codes in the 4000-4999 range.