# Room

## **Create a chat room**

| Name                            | Parameters Description           | Response |
| ------------------------------- | -------------------------------- | -------- |
| `createRoom(options,callback,)` | Please refer to the table below. | N/A      |

<table><thead><tr><th width="210.33333333333331">Name</th><th width="163">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>creation_content</code></td><td><code>CreationContent</code></td><td>Extra keys, such as <code>m.federate</code>, to be added to the content of the <code>m.room.create</code> event. The server will overwrite the following keys: <code>creator</code>, <code>room_version</code>. Future versions of the specification may allow the server to overwrite other keys.</td></tr><tr><td><code>initial_state</code></td><td><p></p><p><code>StateEvent</code>: Please refer to the table below</p></td><td><p>A list of state events to set in the new room. This allows the user to override the default state events set in the new room. The expected format of the state events are an object with type, state_key and content keys set.</p><p>Takes precedence over events set by <code>preset</code>, but gets overridden by <code>name</code> and <code>topic</code> keys.</p></td></tr><tr><td><code>invite</code></td><td><code>string</code></td><td>A list of user IDs to invite to the room. This will tell the server to invite everyone in the list to the newly created room.</td></tr><tr><td><code>name</code></td><td><code>string</code></td><td>If this is included, an <code>m.room.name</code> event will be sent into the room to indicate the name of the room. See Room Events for more information on <code>m.room.name</code>.</td></tr><tr><td><code>preset</code></td><td><code>enum</code></td><td><p> </p><p>Convenience parameter for setting various default state events based on a preset.</p><p>If unspecified, the server should use the <code>visibility</code> to determine which preset to use. A visbility of <code>public</code> equates to a preset of <code>public_chat</code> and <code>private</code> visibility equates to a preset of <code>private_chat</code>.</p><p>One of: <code>[private_chat, public_chat, trusted_private_chat]</code>.</p></td></tr><tr><td><code>room_alias_name</code></td><td><code>string</code></td><td><p> </p><p>The desired room alias local part. If this is included, a room alias will be created and mapped to the newly created room. The alias will belong to the <em>same</em> node which created the room. For example, if this was set to “foo” and sent to the node “example.com” the complete room alias would be <code>#foo:example.com</code>.</p><p>The complete room alias will become the canonical alias for the room and an <code>m.room.canonical_alias</code> event will be sent into the room.</p></td></tr><tr><td><code>topic</code></td><td><code>string</code></td><td>If this is included, an <code>m.room.topic</code> event will be sent into the room to indicate the topic for the room. See Room Events for more information on <code>m.room.topic</code>.</td></tr><tr><td><code>visibility</code></td><td><code>enum</code></td><td><p>A <code>public</code> visibility indicates that the room will be shown in the published room list. A <code>private</code> visibility will hide the room from the published room list. Rooms default to <code>private</code> visibility if this key is not included. NB: This should not be confused with <code>join_rules</code> which also uses the word <code>public</code>.</p><p>One of: <code>[public, private]</code>.</p></td></tr></tbody></table>

| Name        | Type     | Description                                                     |
| ----------- | -------- | --------------------------------------------------------------- |
| `content`   | `object` | The content of the event.                                       |
| `state_key` | `string` | The state\_key of the state event. Defaults to an empty string. |
| `type`      | `string` | The type of event to send.                                      |

## Query DM room by User ID

| Name                 | Parameters Description | Response                 |
| -------------------- | ---------------------- | ------------------------ |
| `findDMRoomByUserId` | `userId`: user Id      | dm\_rooms: room Id array |

## Join a chat room

| Name                                              | Parameters Description                               | Response |
| ------------------------------------------------- | ---------------------------------------------------- | -------- |
| `joinRoom(roomIdOrAlias, opts, callbackCallback)` | roomIdOrAlias: The room identifier or alias to join. | N/A      |

## Leave the chat room

| Name                     | Parameters Description                            | Response |
| ------------------------ | ------------------------------------------------- | -------- |
| `leave(roomId,callback)` | <p>roomId: room id</p><p>callback (optional)：</p> | N/A      |

## Invite user to the room

| Name                             | Parameters Description                                                  | Response |
| -------------------------------- | ----------------------------------------------------------------------- | -------- |
| `invite(roomId,userId,callback)` | <p>roomId: room id</p><p>userId: user id</p><p>callback (optional)：</p> | N/A      |

## **Revoke invitation**

<table><thead><tr><th width="248.33333333333331">Name</th><th>Parameters Description</th><th>Response</th></tr></thead><tbody><tr><td><code>revoke(roomId, userId, reason, callback)</code></td><td><p>roomId: room ID;</p><p>userId: user id；reason(optional): string;</p><p>callback(optional): function</p></td><td>N/A</td></tr></tbody></table>

## Remove user from a room

Remove the user from the room.

| Name                                  | Parameters Description                                                                              | Response |
| ------------------------------------- | --------------------------------------------------------------------------------------------------- | -------- |
| `kick(roomId,userId,reason,callback)` | <p>roomId: room id</p><p>userId: user id</p><p>reason: reason string</p><p>callback (optional):</p> | N/A      |

## Ban user from a room

As the room owner, you can ban users, effectively removing them from the room and preventing their re-entry.

| Name                                 | Parameters Description                                                                              | Response |
| ------------------------------------ | --------------------------------------------------------------------------------------------------- | -------- |
| `ban(roomId,userId,reason,callback)` | <p>roomId: room id</p><p>userId: user id</p><p>reason: reason string</p><p>callback (optional):</p> | N/A      |

## Modify the user's own nickname in a room

| Name                                                  | Parameters Description                                                                           | Response |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------ | -------- |
| `setNickName(roomId,userId,membershipValue,nickName)` | <p>roomId: room id</p><p>userId: user id</p><p>membershipValue:</p><p>nickName: new nickname</p> | N/A      |

## Modify room name

| Name                                 | Parameters Description                                                      | Response  |
| ------------------------------------ | --------------------------------------------------------------------------- | --------- |
| `setRoomName(roomId, name,callback)` | <p>roomId: room id</p><p>name: new room name</p><p>callback (optional):</p> | event\_id |

## **Delete room**

<table><thead><tr><th>Name</th><th width="260.3333333333333">Parameters Description</th><th>Response</th></tr></thead><tbody><tr><td><code>deleteRoom</code></td><td>roomId: room ID</td><td>N/A</td></tr></tbody></table>
