j3k0 / ganomede-chat

Ganomede multi-rooms chat service
0 stars 0 forks source link

Chat

Multi-rooms chat service.

Chat is organized into "rooms". Each room has a type and a list of players allowed to participate.

Relations

Configuration

Variables available for service configuration (see config.js):

Links with DBs and other services:

Optional link to the usermeta database containing user policies (see policies.md)

Statsd options (used for monitoring).

AuthDB

UsermetaDB

Contains the policies (banned, blocked users, chat disabled, etc)

API

All "room" related calls require a valid authToken, either:

Rooms [/chat/v1/auth/:authToken/rooms]

Create a room [POST]

Create a room with a given configuration (or return the one that already exists and update its ttl).

body (application/json)

{
    "type": "triominos/v1",
    "users": [ "alice", "bob" ]
}

response [200] OK

{
    "id": "triominos/v1/alice/bob",
    "type": "triominos/v1",
    "users": [ "alice", "bob" ],
    "messages": []
}

response [403] Forbidden

When linked to users service, will perform ban check. Banned :usernames will receive 403 error no matter validity of a token.

design note

Room is gonna expire 60 days after last POST.

Room's id is formed using following code:

"#{body.type}/#{body.users.sort().join('/')}"

Room [/chat/v1/auth/:authToken/rooms/:roomId]

+ Parameters
    + authToken (string, required) ... Authentication token
    + roomId (string, required) ... URL encoded Room ID

Retrieve content of a room [GET]

response [200] OK

{
    "id": "triominos/v1/alice/bob",
    "type": "triominos/v1",
    "users": [ "alice", "bob" ],
    "messages": [{
        "timestamp": 1429084002258,
        "from": "alice",
        "type": "text",
        "message": "Hey bob! How are you today?"
    }, {
        "timestamp": 1429084002258,
        "from": "bob",
        "type": "text",
        "message": "Hi Alice :)"
    }, {
        "timestamp": 1429084002258,
        "from": "bob",
        "type": "text",
        "message": "Good thanks, let's play"
    }, {
        "timestamp": 1429084002258,
        "from": "$$",
        "type": "event",
        "message": "game_started"
    }]
}

response [404] Not found

No room found with given ID.

response [401] Unauthorized

If authToken is invalid or user isn't a participant in the room, and not API_SECRET.

Messages [/chat/v1/auth/:authToken/rooms/:roomId/messages]

+ Parameters
    + authToken (string, required) ... Authentication token
    + roomId (string, required) ... URL encoded Room ID

Add a message [POST]

Append a new message to the room and updates room's TTL. If the number of messages in the room exceeds MAX_MESSAGES, the oldest will be discarded.

body (application/json)

{
    "timestamp": 1429084016939,
    "type": "txt",
    "message": "Hey bob! How are you today?"
}

response [200] OK

response [401] Unauthorized

If authToken is invalid or user isn't a participant in the room, and not API_SECRET.

response [403] Forbidden

When linked to users service, will perform ban check. Banned :usernames will receive 403 error no matter validity of a token.

response [404] Not Found

No room found with given ID.

design note

A notification will be sent to all users in the room (except the sender of the message and those that blocked him).

{
    "from": "chat/v1",
    "type": "message",
    "data": {
        "timestamp": 1429084002258,
        "from": "bob",
        "type": "text",
        "message": "Good thanks, let's play"
    }
    "push": {…} // optional, will contain whatever is in `req.body.push`.
}

System Messages [/chat/v1/auth/:apiSecret/system-messages]

Add a message [POST]

Join a room, append a new message and updates its TTL. If the number of messages in the room exceeds MAX_MESSAGES, the oldest will be discarded.

body (application/json)

{
    "type": "triominos/v1",
    "users": [ "alice", "bob" ]
    "timestamp": 1429084016939,
    "message": "ALICE_DISCONNECTED"
}

response [200] OK

design note

Response codes and design notes as for the /messages entrypoint.