---
# System prepended metadata

title: Lalesocket

---

# Lalesocket

## Websocket Connection 
websocket url : `ws://laledev6.flowring.com:8000/_lalesockets/client/v1_alpha/stream/{$matrix_token}?device_id={your_device_id}`

* `device_id` will be your `conn_id`
* if `device_id == None` , server will generate random `device_id`


# List of Websocket Payload

## Get user profile
get user profile
```json
{
    "module": "user",
    "method": "profile",
    "params" : {
        "user_lists" : ["@jantest:laledev6.flowring.com","@jantest3:laledev6.flowring.com","@jantest2:laledev6.flowring.com","@jantest4:laledev6.flowring.com"]
    }, 
    "args" : {	
        "friend_type": "friend_invite"
    }
}
```

## Send a friend request 
Send a friend request
```json
{
    "module": "user",
    "method": "friend_request",
    "params": {
        "receiverUserId": "@jantest2:laledev6.flowring.com",
        "senderUserId": "@jantest4:laledev6.flowring.com", 
        "lale_jwt": "lale_token"
    }
}
```

## Send a friend request response
Send a friend request response
```json
{
    "module": "user",
    "method": "response_friend_request",
    "params": {
        "receiverUserId": "@jantest2:laledev6.flowring.com",
        "senderUserId": "@jantest4:laledev6.flowring.com", 
        "isApproved": true,
        "lale_jwt": "lale_token"
    }
}
```

## Send a text message
Send a text message
```json
{
    "module": "room",
    "method": "send_text",
    "params": {
        "room_id": "!zvpULVVcwTSKecWcri:laledev6.flowring.com",
        "event_type": "m.room.message",
        "content": {
            "msgtype": "m.text",
            "body": "Hi, nice talk to you!"
        }
    }
}
```

## Send a file message
1. client **should upload** the file using [`Matrix API`](!https://matrix.org/docs/spec/client_server/latest#post-matrix-media-r0-upload). 
    - client received file `matrix url` from Matrix API. 
2. client **should provide valid metadata** of the file!

```json
{
    "module": "room",
    "method": "send_file",
    "params": {
        "room_id": "!zvpULVVcwTSKecWcri:laledev6.flowring.com",
        "event_type": "m.room.message",
        "content": {
            "body": "job_chat_template.docx",
            "filename": "default-filename.docx",
            "info": {
                "mimetype": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                "size": 23299
            },
            "msgtype": "m.file",
            "url": "mxc://laledev6.flowring.com/DbcRoqSUdurUglNUTVKBbJnt"
        }
    }
}
```

## Send an image message
1. client **should upload** the image using [`Matrix API`](!https://matrix.org/docs/spec/client_server/latest#post-matrix-media-r0-upload). . 
    - client received file `matrix url` from Matrix API. 
2. client **should provide valid metadata** of the image!

```json
{
    "module": "room",
    "method": "send_image",
    "params": {
        "room_id": "!zvpULVVcwTSKecWcri:laledev6.flowring.com",
        "event_type": "m.room.message",
        "content": {
            "body": "1280px-Yes_NCTU_main_entrance_lake.jpg",
            "filename": "default-image.jpg",
            "info": {
                "mimetype": "image/jpeg",
                "h": 960,
                "w": 1280,
                "size": 257102
            },
            "msgtype": "m.image",
            "url": "mxc://laledev6.flowring.com/jdHDCsbfQaQkfBZYStuhLGvg"
        }
    }
}
```
## Create or Join a Secret Group 
Create or Join secret group. 
1. Create room if the room is not exist.
2. Join room if the room is exist.

Flow: 
```
1. client send payload to WS 
user_id, password 

2. WS check to LALE if room is exist or not (by password)
password 
2.1 Room is exist 
2.1.1. if a room is exist, lale will return room_id & group_id & usersList. 
2.1.2. Then user_id join to the room_id (call matrix API)
2.1.3. notify Lale, that user has joined the group/room (private/room/enter/{userId})
room_id, group_id, password, UserList (follow the original lale format)

2.2 Room is not exist
2.2.1 if a room is not exist, create a room (call matrix API). I will received a room_id from matrix 
2.2.2 Notify Lale, by calling private/room/enter/{userId}
groupId = empty, room_id = room_id, password = password 
userList = "@jantest:laledev6.flowring.com" (TBC)

3. return everything from lale to client
```

```json
{
    "module": "room",
    "method": "create_join_secret_group",
    "params": {
        "time": "2021-11-03T05:21:24.401Z",
        "password": "0206",
        "lale_jwt" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJqYW50ZXN0MiIsImV4cCI6MTYzNzYzMjg4MCwiaWF0IjoxNjM3NjMwMTgwfQ.zMxHjagE0Wfic8InzewCwWxvZXnZY3ebGyjzRRJDOMc"
    }
}
```
## Leave a secret/private room 
leave a secret group 

```json=
{
    "module": "room",
    "method": "leave_secret_group",
    "params": {
        "password": "0206",
        "lale_jwt" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJqYW50ZXN0MiIsImV4cCI6MTYzNzYzMjg4MCwiaWF0IjoxNjM3NjMwMTgwfQ.zMxHjagE0Wfic8InzewCwWxvZXnZY3ebGyjzRRJDOMc"
    }
}
```

## Create a special room
Create a new room with lale setting.

lale setting 
```
roomType : 1(normal), 4(work)
```
```json
{
    "module": "room",
    "method": "create_special_room",
    "params": {
        "userId": "@jantest2:laledev6.flowring.com",
        "roomType": 4, 
        "name": "My work room", 
        "invite": ["@jantest3:laledev6.flowring.com","@jantest:laledev6.flowring.com"], 
        "lale_jwt": "lale_token"
    }
}
```


## Create a group
Create a new group and invited users directly join (couple with lale group settings). 
```json
{
    "module": "room",
    "method": "create_group",
    "params": {
        "adminId": "@jantest2:laledev6.flowring.com",
        "lastUpdatedTime": "2021-11-03T05:21:24.401Z",
        "name": "My new room",
        "announcement": "my announcement", //Optional
        "imageData": "encoded string",  //Optional
        "roomType": 0,
        "userList": ["@jantest:laledev6.flowring.com","@jantest3:laledev6.flowring.com"],
        "lale_jwt" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJqYW50ZXN0MiIsImV4cCI6MTYzNTkyMjMxMywiaWF0IjoxNjM1OTE5NjEzfQ.SNL2Wt0PQhBiIDbv6hfglUoC0n0rkacCM6I9nYJDM_c"
    }
}
```

## Add group members
Add new members into a group. Invited users directly join (couple with lale group settings). 

**Make sure the `adminId` has authorize to invite users**

**Input valid `roomId` and `groupId`**
```json
{
    "module": "room",
    "method": "add_group_members",
    "params": {
        "adminId": "@jantest2:laledev6.flowring.com",
        "roomId": "!pDszxyBrGxxNzELRhS:laledev6.flowring.com",
        "groupId": "+room2021110500000003:laledev6.flowring.com",
        "userList": [
            "@jantest:laledev6.flowring.com","@jantest3:laledev6.flowring.com"
        ],
        "lale_jwt" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJqYW50ZXN0MiIsImV4cCI6MTYzNTkyMjMxMywiaWF0IjoxNjM1OTE5NjEzfQ.SNL2Wt0PQhBiIDbv6hfglUoC0n0rkacCM6I9nYJDM_c"
    }
}
```

## Remove group members
Remove members from a group. removed users directly leave (couple with lale group settings). 

**Make sure the `adminId` has authorize to kick users**

**Input valid `roomId` and `groupId`**
```json
{
    "module": "room",
    "method": "remove_group_members",
    "params": {
        "adminId": "@jantest2:laledev6.flowring.com",
        "roomId": "!pDszxyBrGxxNzELRhS:laledev6.flowring.com",
        "groupId": "+room2021110500000003:laledev6.flowring.com",
        "userList": [
            "@jantest:laledev6.flowring.com","@jantest3:laledev6.flowring.com"
        ],
        "lale_jwt" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJqYW50ZXN0MiIsImV4cCI6MTYzNTkyMjMxMywiaWF0IjoxNjM1OTE5NjEzfQ.SNL2Wt0PQhBiIDbv6hfglUoC0n0rkacCM6I9nYJDM_c"
    }
}
```

## Get Private Room
Get a room related with friend. If there is no room available, server automatically create a room and both users in the room. 
```json
{
    "module": "room",
    "method": "get_private_room",
    "params": {
        "user_id": "@jantest3:laledev6.flowring.com"
    }
}
```

## Create a room
Create a new room with only creator in the room
```json
{
    "module": "room",
    "method": "create_room",
    "params": {
        "user_id": "@jantest2:laledev6.flowring.com",
        "name": "My new room",
        "is_public": true
    }
}
```

## Invite users to join a room 
Invite user to join a room. 
**Params have to be valid!**
```json
{
    "module": "room",
    "method": "invite_room",
    "params": {
        "room_id": "!zvpULVVcwTSKecWcri:laledev6.flowring.com",
        "user_id": ["@jantest:laledev6.flowring.com","@jantest3:laledev6.flowring.com"]
    }
}
```

## Join a room 
Join a room 
**params have to be valid!**
```json
{
    "module": "room",
    "method": "join_room",
    "params": {
        "room_id": "!NeAoQKAdIwnlEYZLel:laledev6.flowring.com"
    }
}
```

## leave a room 
leave a room 
**params have to be valid!**
```json
{
    "module": "room",
    "method": "leave_room",
    "params": {
        "room_id": "!NeAoQKAdIwnlEYZLel:laledev6.flowring.com"
    }
}
```