Skip to content

PlicPloucPloc/PLIC-Chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swappart Chat Service Doc

API

Create a room

To create a room, you need to be authenticated POST /rooms

{
  "users": uuid[],
  "apartment_id": number|null
}

Response

{
  "error_message": null|string,
  "data": number | null 
}

Get user rooms

GET /rooms

Response

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
    }
  }[]
}

Add/Remove participants to room

PUT /rooms

{
  "room_id": number,
  "users_to_add": uuid[],
  "users_to_remove": uuid[]
}

Response

{
  "error_message": null|string,
  "data": null
}

Remove a room

DELETE /rooms/:id

Response

{
  "error_message": null|string,
  "data": null
}

Get Room Infos/messages

GET /rooms/:id

Response

{
  "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
}

Websocket

Connection

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...

Data Transfer Types

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
}

MsgSendData

{
  "room_id": int,
  "message": string,
  "message_temp_id": front-generated-string
}

Responses

{
  "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

Message Received Payload

{
  "type": "MessageReceived",
  "data": {
    "room_id": int,
    "sender_id": string, (Supabase ID)
    "message": string
  }
}

MessageSentConfirmation

{
  "type": "MessageSentConfirmation",
  "data": {
    "confirmed": bool,
    "reason": string,
    "message_id": string
  }
}

Codes

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.

About

Chat service for the 1year project for EPITA

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors