Chat Room

AI Tools

In the Chat Room, you can add additional information called options that is automatically synchronized by each participant in the conversation. It is important that the amount of data stored in options is kept minimize to ensure the quickest synchronization possible. You can use options 'tag a room' to change background color, or you can add a latitude as well as longitude.

options consist string key-value pairs

Create or Get 1-on-1 Chat Room with Metadata

The 1-on-1 Chat Room is ideal case when you want a conversation that requires 2 users. You need to set userId to identify the opponent that you want to chat to. If a Chat Room with predefined userId doesn't exist, it will create a new one. Otherwise, if Chat Room with predefined userId already exists, it will return that room and add requester and the opponents as participants. For further information you can see this Chat Room Type.

Below is the example code:

Swift
Copy

Where:

  • withUser: A User identifier that will be used to identify a user and used whenever another user need to chat with this user. It can be anything, whether is is user's email, your user database index, etc. As long as it is unique and a string.
  • options: metadata that can be as additional information to Chat Room, which consist key-value, for example key: background, and value: red.

Create Group Chat Room with Metadata

When you want your many users to chat together in a 1-on-1 Chat Room, you need to create Group Chat Room. Basically Group Chat Room has the same concept as 1-on-1 Chat Room, but the different is that Group Chat Room will target array of userIds in a single method.

Swift
Copy

Where:

  • roomName: group name
  • userIds: list of userId
  • avatarUrl: avatar url for group Chat Room
  • options: metadata that can be as additional information to Chat Room, which consists of key-value, for example, key: background, and value: red.

You can get created chat room from local data:

Swift
Copy

Create or Get Channel with Metadata

Creating Channel Chat Room is ideal for a use case that requires a lot of number participants.

You need to set uniqueId to identify a Channel Chat Room. If a Chat Room with predefined uniqueId doesn't exist, it will create a new one with requester as the only one participant. Otherwise, if Chat Room with predefined uniqueId already exists, it will return that room and add requester as a participant.

When the room doesn't exist at the very first call and you do not send avatarUrl and/or roomName, it will use the default value. But, after the second call (room does exist) and you send avatarUrl and/or roomName, it will be updated to that value.

Swift
Copy

You can get created chat room from local data:

Swift
Copy

Where :

  • uniqueId : identity of a Channel
  • options: metadata that can be as additional information to Chat Room, which consists of key-value, for example, key: background, and value: red.

Get Chat Room by Id (Enter Existing Chat Room)

You can enter existing Chat Room by using roomId and create your own chat UI. You can get roomId from RoomModel object that you have created before or participated for 1-on-1, Group Chat or Channel. As a return, you will get a pair of a Chat Room and List of Comments that you can use to init data comment for the first time. As a reference, you can see the details of implementation in this sample.

You can use it to 1-on-1 Chat Room, Group Chat Room, or Channel and here's how to get a Chat Room by roomId:

Swift
Copy

Get Chat Room Information

You can get more than one Chat Room, by passing list of roomId, for uniqueIds will deprecate soon, for now you can set same as roomIds. You can see the participant for each room by set showParticipants to true, or you can set false to hide participant data in each room.

Swift
Copy

Where:

  • withID : array of room id
  • showParticipant: show participant in room, default is false (optional)

You can get Chat Rooms from your local data, for example:

Swift
Copy

Get Chat Room List

Get Chat Room list is an ideal case to retrieve all Chat Rooms that Qiscus Account has. This shows up to 100 data per page.

Swift
Copy

Update Chat Room with Metadata

To update your Chat Room metadata, you need roomId, your Chat Room roomName, your Chat Room avatarUrl, and options, for example:

Swift
Copy

Where:

  • roomId: Chat Room Id
  • roomName: room name
  • avatarUrl: avatar URL
  • options (String:any): metadata that can be as additional information to Chat Room, which consist key-value, for example key: background, and value: red.

Update chat room API works only for Group chat and Channel

Get Participant List In Chat Room

To get participant list in Chat Room, you need roomUniqueId, you can get roomUniqueId within chat room object. By default you get 100 participants, for example:

Swift
Copy

You can get advance by adding some parameter, for example you can order the list based on either ascending (asc) or descending (desc), for example:

Swift
Copy

Where:

  • roomUniqueId: unique Id each of Chat Room
  • offset: number of offset
  • sorting: filtering based on ascending (asc) or descending ( desc), by default refer to asc.

Default return 100 participants for each page.

Add Participant in Chat Room

You can add more than a participant in Chat Room by calling this method addParticipant. You can pass multiple userIds. Once a participant succeed join the Chat Room, they get a new Chat Room in their Chat Room list.

Swift
Copy

Remove Participant in Chat Room

You can remove more than a participant in Chat Room by calling this method removeRoomMember. You can pass multiple userId. Once a participant is removed from the Chat Room, they will not find related Chat Room in their Chat Room list.

Swift
Copy

Get Total Unread Count in Chat Room (Deprecated)

You can get total unread count in every Chat Room. Ideally, this case is used when you want to show badge icon, for example getting total unread count please see the code below:

Swift
Copy
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard