Learn how to send and receive messages, mark messages as delivered or read, etc.
addDelegate()
method. The event delegate enables the app to listen to message events associated with receiving a message, delivery receipts, and read receipts.
QBChatDelegate
methods in your chat controller to track events in your chat.
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.save_to_history
as true
to save the message on the server. If the save_to_history
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.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 |
---|---|---|
message | yes | Specifies message fields that should be set. |
message
:
Field | Required | Description |
---|---|---|
text | no | Message text. |
customParameters | no | Extra data. Specify any key-value pairs. In each pair, the key and value are both string values. Set the save_to_history as 1 to save a message to the history. |
messages(withDialogID:extendedRequest:)
method. The request below will return messages for a specific dialog, sorted by the date_sent
field in descending order, limited to 50 dialogs on the page.
mark_as_read
parameter as 1
in the extendedRequest
. If you decide not to mark chat messages as read, just set the mark_as_read
parameter as 0
.extendedRequest
dictionary.
If you want to get a paginated list of messages from the server, you can set the key-value parameters in the extendedRequest
dictionary.
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. |
updateMessage(withID:text:dialogID:)
method below.
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 forAllUsers
parameter to true
.
Argument | Required | Description |
---|---|---|
messages | yes | A set of strings with messages IDs |
forAllUser | yes | A boolean parameter. Delete message for everyone. Set it as true to perform. Only the owner can do it. |
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.chatDidDeliverMessage(messageID:dialogID:)
method of the QBChatDelegate
delegate.
mark(asDelivered:)
method to mark a message as delivered. As a result, the server will notify a sender about the delivery receipt.
Argument | Required | Description |
---|---|---|
receivedMessage | yes | A message received from the sender. |
markable
as true
using 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 false
or omitted, then you can notify a sender about the delivery receipt using the mark(asDelivered:)
method.
messages(withDialogID:)
method. See this section to learn how to retrieve chat history.delivered_ids
field in the message model, on the server, by using the method below. As a result, the ID of the user who has received the message will be added to the array of delivered_ids
field. However, the server won’t notify the user about the change in the message model.
Argument | Required | Description |
---|---|---|
markMessagesAsDeliveredSet | yes | A set of strings with messages IDs. |
dialogID | yes | The ID of the dialog. |
chatDidReadMessage(messageID:dialogID:readerID:)
method of the QBChatDelegate
is used.
read()
method to mark a message as read. As a result, the server will notify a sender about the read receipt.
Argument | Required | Description |
---|---|---|
receivedMessage | yes | A message received from the sender. |
messages(withDialogID:)
method. See this section to learn how to retrieve chat history.read_ids
field in the message model, on the server, by using the method below. As a result, the ID of the user who has read the message will be added to the array of read_ids
field. However, the server won’t notify the user about the change in the message model.
Argument | Required | Description |
---|---|---|
markMessagesAsReadSet | yes | A set of strings with received messages IDs. |
dialogID | yes | The ID of the dialog that received messages. |
onUserIsTyping(userID:)
method of the delegate.
onUserStoppedTyping(userID:)
method of the delegate.
sendUserIsTyping()
method. As a result, the server will notify a recipient about the event.
sendUserStopTyping()
method. As a result, the server will notify a recipient about the event.
chatDidReceiveSystemMessage()
callback of QBChatDelegate
. See this section to learn how to add QBChatDelegate
.
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 |
---|---|
message | Specifies system message fields that should be set. |
message
:
Field | Required | Description |
---|---|---|
recipientID | yes | ID of the recipient. |
customParameters | no | Extra data. Specify one or more key-value pairs. In each pair, the key and value are both string values. |