Learn how to send and receive messages, mark messages as delivered or read, etc.
QB.chat.onMessageListener
to receive messages in real-time. The event listener enables the app to listen to the incoming message.
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.Argument | Required | Description |
---|---|---|
dialogJid | yes | Room JID. JID (Jabber ID) of XMPP room in the XMPP server. Empty for a privatе dialog. Generated automatically by the server after dialog creation. You can get JID from the dialog ID. The JID format is the following: <app_id>-<dialog_id>@muc.chat.quickblox.com |
message | yes | Specifies message fields that should be set. |
save_to_history: 1
to save the message on the server. If you set save_to_history: 0
, the message won’t be saved on the server. However, the message will be delivered to the user in either case.message
. 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.
Argument | Required | Description |
---|---|---|
jidOrUserId | yes | User ID or Room JID. JID (Jabber ID) of XMPP room in the XMPP server. Empty for a privatе dialog. Generated automatically by the server after dialog creation. You can get JID from the dialog ID. The JID format is the following: <app_id>-<dialog_id>@muc.chat.quickblox.com . |
message | yes | Specifies message fields that should be set. |
message
:
Field | Required | Description |
---|---|---|
type | no | Message type. Possible values: chat and groupchat. |
body | no | A message text. |
extension | no | Extra data. Specify any key-value pairs. In each pair, the key and value are both string values. Set save_to_history as true to save the message on the server. |
list()
method. The request below will return messages for a specific dialog, sorted by the date_sent
field in descending order, limited to 100 messages.
markAsRead
parameter as true
. If you decide not to mark chat messages as read, just set markAsRead
parameter as false
.params
:
Pagination parameter | 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 operator | Applicable to types | Description |
---|---|---|
sort_asc | All types | Search results will be sorted in ascending order by the specified field. |
sort_desc | All types | Search results will be sorted in descending order by the specified field. |
update()
method.
Argument | Required | Description |
---|---|---|
messageId | yes | ID of the message being updated. |
updateParams | yes | Specifies key-value fields that should be updated. |
function() | yes | Specifies the callback function which receives the response from the QuickBlox server for the updating request. |
occupantIDs
can delete a message from the dialog. As a result, the message will be deleted from the current user history, without affecting the histories of other users.
The owner of the dialog can completely remove messages from all users’ histories. This is achieved by setting the force
to 1
.
params
:
Argument | Required | Description |
---|---|---|
messageId | yes | ID of the message. |
params | yes | Specifies params fields that should be set. |
CONFIG
object and then call the init()
method. See this section to learn how to enable the stream management.
Thus, to handle the event when the message is considered as sent, the onSentMessageCallback()
is used.
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.onMessageListener
. See this section to learn how to add the listener. As a result, when a user receives a message, the SDK receives the onDeliveredStatusListener()
callback.
sendDeliveredStatus()
method to mark a message as delivered. As a result, the server will notify a sender about the delivery receipt.
markable
parameter and pass it within the message
to the send()
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 not set or omitted, then you can notify a sender about the delivery receipt using the sendDeliveredStatus()
method.
onDeliveredStatusListener
callback 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 list()
method. See this section to learn how to retrieve chat history.QB.chat.onMessageListener
. See this section to learn how to add the listener. As a result, when a user receives a message, the SDK receives the onReadStatusListener()
callback.
sendReadStatus()
method to mark a message as read. As a result, the server will notify a sender about the read receipt.
list()
method. See this section to learn how to retrieve chat history.QB.chat.onMessageListener
. See this section to learn how to add the listener. As a result, when a user is typing or stopped typing a message, the SDK receives the onMessageTypingListener()
callback.
sendIsTypingStatus()
method. As a result, the server will notify a recipient about the event.
sendIsStopTypingStatus()
method. As a result, the server will notify a recipient about the event.
Argument | Required | Description |
---|---|---|
jid | yes | Room JID. JID (Jabber ID) of XMPP room in the XMPP server. Pass room JID for type=2 (group dialog). Generated automatically by the server after dialog creation. You can get JID from the dialog ID. The JID format is the following: <app_id>-<dialog_id>@muc.chat.quickblox.com"dialog ). |
userID | yes | ID of the opponent. Pass opponet ID for type=3 (private dialog). |
onSystemMessageListener
callback.
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.
Argument | Description |
---|---|
opponentId | ID of the opponent. |
message | Specifies system message fields that should be updated. |
message
:
Fields | Required | Description |
---|---|---|
body | no | A system notification text. |
extension | no | Extra data. Specify one or more key-value pairs. In each pair, the key and value are both string values. |