Learn how to send and receive messages, mark messages as delivered or read, etc.
join()
method before you start chatting in a dialog. Once the dialog is joined, you can receive/send messages. See this section to learn how to join the dialog.saveToHistory
as true
to save the message on the server. If the saveToHistory
is set as false
, the message won’t be saved on the server. However, the message will be delivered to the user in either case.properties
. Using these items, you can implement the ability for a user to send self-location information to another user or notification messages signifying that a user has left a group, etc.
sendMessage()
method accepts one argument of the object type that has the following fields:
Field | Required | Description |
---|---|---|
dialogId | yes | The ID of a dialog. |
body | no | A message text. |
properties | no | Extra data. Specify any key-value pairs. In each pair, the key and value are both string values. |
saveToHistory | no | Specifies if the message will be saved on the server. Set the saveToHistory as true to save the message on the server. |
getDialogMessages()
method. The request below will return messages for a specific dialog, sorted by the date_sent
field in descending order.
markAsRead
parameter as true
. If you decide not to mark chat messages as read, just set markAsRead
parameter as false
or omit the parameter.Pagination parameters | Description |
---|---|
skip | Skip N records in search results. Useful for pagination. Default (if not specified): 0. |
limit | Limit search results to N records. Useful for pagination. Default value: 100. |
Search operators | Applicable to types | Applicable to fields | Description |
---|---|---|---|
lt | number, string, date | date_sent, sender_id, recipient_id, updated_at | Less Than operator. |
lte | number, string, date | date_sent, sender_id, recipient_id, updated_at | Less Than or Equal to operator. |
gt | number, string, date | date_sent, sender_id, recipient_id, updated_at | Greater Than operator. |
gte | number, string, date | date_sent, sender_id, recipient_id, updated_at | Greater Than or Equal to operator. |
ne | number, string, date | _id, message, date_sent, sender_id, recipient_id | Not Equal to operator. |
in | number, string, date | date_sent, sender_id, recipient_id | IN array operator. |
nin | number, string, date | date_sent, sender_id, recipient_id | Not IN array operator. |
or | number, string, date | date_sent, sender_id, recipient_id | All records that contain a value 1 or value 2. |
ctn | string | message | All records that contain a particular substring. |
Sort options | Applicable to types | Description |
---|---|---|
ascending | All types | Sort results in the ascending order by setting the ascending as true. |
decsending | All types | Sort results in the descending order by setting the ascending as false. |
login()
because the Stream Management is initialized while Chat login is performed.The Stream Management defines an extension for active management of a stream between a client and server, including features for stanza acknowledgments.QB.chat.EVENT_TYPE.MESSAGE_DELIVERED
event.
markMessageDelivered()
method to mark a message as delivered. As a result, the server will notify a sender about the delivery receipt.
markable
as true
using the sendMessage()
method if you want, as a sender, to receive message delivery receipts from other recipients. Thus, the markable
parameter enables the sender to request the delivery receipt. It also enables the recipient to confirm the message delivery. However, if markable
is false
or omitted, then you can notify a sender about the delivery receipt using the markMessageDelivered()
method.
QB.chat.EVENT_TYPE.MESSAGE_DELIVERED
event is received.When a message is marked as delivered, the IDs of users who have received the message are stored in the message model, on the server. Thus, you can request a chat history from the server to get to know who received the message using the getDialogMessages()
method. See this section to learn how to retrieve chat history.QB.chat.EVENT_TYPE.MESSAGE_READ
event.
markMessageRead()
method to mark a message as read. As a result, the server will notify a sender about the read receipt.
getDialogMessages()
method. See this section to learn how to retrieve chat history.QB.chat.EVENT_TYPE.USER_IS_TYPING
event.
QB.chat.EVENT_TYPE.USER_STOPPED_TYPING
event.
sendIsTyping()
method. As a result, the server will notify a recipient about the event.
sendStoppedTyping()
method. As a result, the server will notify a recipient about the event.
QB.chat.EVENT_TYPE.RECEIVED_SYSTEM_MESSAGE
event. See this section to learn how to subscribe to this event.
System messages are also not shown in the dialog history and, consequently, are not stored on the server. This means that these messages will be delivered only to online users. Send system messages using the sendSystemMessage()
method.
sendSystemMessage()
method accepts one argument of the object type that has the following fields:
Field | Required | Description |
---|---|---|
recipientId | yes | ID of the recipient. |
properties | no | Extra data. Specify any key-value pairs. In each pair, the key and value are both string values. You can’t specify any object, because it won’t be passed as an argument. |