Message

You can send a message in a chat room, and other user get the message, push notification, and unread count as long as they are participant in that chat room.

Qiscus Chat SDK has 3 statues, which are sent, delivered, read for a message. Once message is sent, the OnReceiveMessage event handler will be called. To understand this part, you can refer to Event Handler section.

Sent, delivered, and read receipt in a message only work on 1-on-1 Chat and Group Chat. Hence, you may not get these message receipts in a Channel type.

In Message, you can add metadata called extras. The extras is automatically synchronized by each participant in a Chat Room.

Sent, delivered, and read receipt in a message only work on 1-on-1 Chat and Group Chat

Send Message

You can send a text message or custom message type. The custom message is the best option to create customized UI message needs by sending structured data, such as when you need to send location message, ticket concert message, a product info, and others UI messages that need to be customized. You need to create CommentModel object first before sending it, for example:

Create CommentModel object, text type:

Swift
Copy

Create CommentModel object, custom type:

Swift
Copy

Where:

  • roomId: Chat Room Identity (Id). You can get this Id in QiscusChatRoom object,
  • text: message text that you send to other participants,
  • type: message type that you can define based your needs. There are reserved rich message types, for example, text, file_attachment, account_linking, buttons, button_postback_response, replay, system_event, card, custom, location, contact_person, and carousel. These types have been taken by Qiscus. So, if you use them, you may face a situation where your structured data will not work. These types are taken for Chat Server API, hence you need to define other type names.
  • payload: payload to define the structured message data. For example, you want to create your own file message, you can fill the payload using this example JSON:
JSON
Copy

You can find how to implement this content in Sample. Another example content you can craft:

JSON
Copy

You can add extras before sending a message, for example

Swift
Copy

Metadata is automatically synchronized by each participant in the Chat Room, it is important that the amount of data stored in metadata is kept to a minimum to ensure the quickest synchronization possible.

Secondly, you can send a message using sendMessage method and need a CommentModel as parameter, for example:

Swift
Copy

Receive Message

When user successfully send a message, other participant receive the message through gotNewComemnt event. You need to implement this event for getting this message, for example:

Swift
Copy

Update Message Read Status

You can set your message status into read. The ideal case of this, is to notify other participants that a message has been read. You need to pass roomId and commentId.

When you have 10 messages, let's say it has message Ids from 1 to 10 and put 10 as the latest message Id. Once you set read message status with the latest message, in this case is 10, your previous messages which are 1 to 9 message Ids, will be updated into read and it will make your unread count become 0.

After succeed send read status, other participants will receive a read event, for further detail you can refer to this section didComment event section.

You can update message read status by calling updateCommentRead() method, for example:

Swift
Copy

Update message read status only work on 1-on-1 Chat and Group Chat.

Load Message with Limit and Offset

You can get previous messages by calling loadComments method, by default you get 20 messages start from your lastCommentId, and also you can use this for load more the older messages, for example:

Swift
Copy

Where:

  • roomId: ChatRoom Id
  • lastComemntId: messageId that you can get from commentModel object

You can a get message from local data, for example:

Swift
Copy

Upload File (% of Process)

You can upload a file by passing data and fileName. In return, you will get URI and progress listener. You can use this listener to create your own uploading process UI, for example:

Swift
Copy

Download Media (The Path and % of Process)

You can download a file by passing url. In return, you will get progress listener. You can use this listener to create your own downloading process UI, for example:

Swift
Copy

Delete Message

You can delete a message by calling this deleteMessage method for example:

Swift
Copy

Clear All Messages in Particular Chat Room

You can clear all message by passing array of roomId or roomUniquesIds. This function will clear all messages only effect on QiscusAccount side, other participants still remain. For example:

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