Message

AI Tools

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 2 statues, which are sent, 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 content. 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 Text Message

You can send a text message by passing the roomId. You can get roomId from QiscusChatRoom object that you have created or participated for 1-on-1, Group Chat or Channel.

Below is a detailed example of how to send a message using text type:

  1. Generate QiscusComment object, and fill the value, roomId and the message:
Java
Copy

2. Send message by passing the qiscusComment object that has created, for example:

Java
Copy

After successfully send a message other participant get the message through OnReceiveMessageevent.

Text message type can contain metadata

Receive Message

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

Java
Copy

This event using eventBus, for further detail using eventBus you can see this event handler section.

Send Custom Message

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, a ticket concert message, a product info, and others UI messages that need to be customized. You need to create QiscusComment object first before sending it, for example:

Generate QiscusComment object, custom type:

Java
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, reply, 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.
  • content: payload to define the structured message data. For example, you want to create your own file message, you can fill the content using this example JSON:
JSON
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 in a minimum to ensure the quickest synchronization possible.

Second, you can send a message using postComment method and you need a QiscusComment as a parameter, for example:

Java
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 to send read status, other participants will receive a read event, for further details you can refer to Event Handler section .

You can update message read status by calling setUserRead method, for example:

Java
Copy

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

Upload File (% of Process)

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

Java
Copy

Load Message with Limit and Offset

You can get previous messages by calling getComments method. By default, you will get 20 messages started from your lastCommentId. You can also use this to load more the older messages, for example:

Java
Copy

Where:

  • roomId: ChatRoom Id,
  • lastCommentId: messageId that you can get from QiscusComment object.

Download Media (The Path and % of Process)

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

Java
Copy

That code only downloads the file without saving information to local data. To save data into local data, you can use this example:

Java
Copy

Delete Message

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

Java
Copy

Where:

  • commentUniqueIds: uniqueId in QiscusComment object,
  • isHardDelete: it will be deprecated soon. But at this moment, you can set true to make your messages gone in the local data, and set false to remain your messages in the local database.

Clear All Messages in Particular Chat Room

You can clear all messages by passing array of roomIds . This function will clear all messages and affected only on QiscusAccount side, while other participants will still remain. For example:

Java
Copy

And optionally, you can delete from your local data as well, for example:

Java
Copy
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard