Title
Create new category
Edit page index title
Edit category
Edit link
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.
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. Ideal case for custom message is for creating custom UI message needs by sending structured data, such as you need to send location message, a ticket concert message, a product info, and others UI message that need to be customized.
Send a text comment:
qiscus.sendComment(roomId, text) .then(function (comment) { // On success }) .catch(function (error) { // On error })Send a custom comment type,
qiscus.sendComment(roomId, text, uniqueId, type, payload, extras) .then(function (comment) { // On success }) .catch(function (error) { // On error })Where:
- roomId: Chat Room Identity (Id), you can get this Id in QiscusChatRoom object
- text: message text that you send to other participant
- uniqueId :temporary id to identify comment data
- type: message type, that you can define freely, there are reserved rich messages type, for example: text, file_attachment, account_linking, buttons, button_postback_response, reply, system_event, card, custom, location, contact_person, carousel. These type have been taken, if you use it you may face your structured data will not work, these type for bot API, hence you need define other type name.
- payload: Payload for defining the structured message data, for example you want to create your own file message, you can fill the content using this example JSON :
{ "url": "https://d1edrlpyc25xu0.cloudfront.net/sampleapp-65ghcsaysse/docs/upload/2sxErjgAfp/Android-Studio-Shortcuts-You-Need-the-Most-3.pdf", "caption": "", "file_name": "Android-Studio-Shortcuts-You-Need-the-Most.pdf"}You can find how to implement this content in Sample. Another example content you can craft:
{ "cards": [ { "header": { "title": "Pizza Bot Customer Support", "subtitle": "[email protected]", "imageUrl": "https://goo.gl/aeDtrS", "imageStyle": "IMAGE" }, ... } ]}You can add extras before sending a message, by intercepting the object into a valid JSON string, for example:
"{\"key1\":\"value1\",\"key2\":\"value2\"}"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.
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:
newMessagesCallback: function (messages) { var message = messages[0] // Do something with message}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 readComment method, for example:
qiscus.readComment(roomId, lastReadCommentId)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
var options = { last_comment_id:10, limit:20}qiscus.loadComments(roomId, options) .then(function (comments) { // On success }) .catch(function (error) { // On error })Where:
roomId: ChatRoom Idoptions: an object with value oflimit: how many message you want to receivelast_comment_id: your starting pointer to receive message
Upload File (% of Process)
You can send a raw file by passing file. In return you will URL and progressEvent, that you can use this listener to create your own uploading process UI, for example:
qiscus.upload(file: File, function (error: Error, progress: ProgressEvent, url: String) { if (error) { // on Error } if (progress) { // Do something when file are still uploading } if (url) { // on Success }})Delete Message
You can delete a message by calling this deleteComments method for example:
qiscus.deleteComment(roomId, commentUniqueIds) .then(function (comment) { // On success }) .catch(function (error) { // On error })Where:
roomId: Chat Room idcommentUniqueIds: unique id of qiscus comment object
Clear All Messages in Particular Chat Room
You can clear all message by passing array roomUniqueIds this clear all messages only effect QiscusAccount side, other participants still remain. For example:
qiscus.clearRoomMessages([roomUniqueIds]) .then(function (rooms) { // On success }) .catch(function (error) { // On error })Qiscus Technology